Can't open Form1 if Form2 is open

Vugar

Registered User.
Local time
Today, 11:12
Joined
Sep 15, 2015
Messages
55
Hi everyone,

I have 2 Forms: Outgoing and Incoming.

Can I make a rule that if "Incoming" is open so I can't open "Outgoing"? and it possible to set msg box: You must closed "Incoming"?

thank you
 
paste this in a module:

Code:
Public Function IsFormLoaded(ByVal strFormName As String) As Boolean
    Dim oAccessObject As AccessObject
    Set oAccessObject = CurrentProject.AllForms(strFormName)
    IsFormLoaded = False
    If oAccessObject.IsLoaded Then
        If oAccessObject.CurrentView <> acCurViewDesign Then IsFormLoaded = True
    End If
    Set oAccessObject = Nothing
End Function
on your "outgoing"form's Open event:

Private sub form_Open(cancel as integer)

if IsFormLoaded("theNameOfYourIncomingForm") Then
msgbox "Unable to open form." & vbcrlf & "Incoming form is open you must close it first."
cancel = true
end if
End Sub
 
Thank you for your reply.

Where put below code?
Code:
Public Function IsFormLoaded(ByVal strFormName As String) As Boolean
Dim oAccessObject As AccessObject
Set oAccessObject = CurrentProject.AllForms(strFormName)
IsFormLoaded = False
If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then IsFormLoaded = True
End If
Set oAccessObject = Nothing
End Function
 
use paste the code in VBE. type Ctrl-F11. on VBE menu Insert->Module, then paste the code.

vbcrlf means carriage return-line feed, this means the text after vbcrlf will appear on the next line of msgbox.
 
Private Sub Form_Open(Cancel As Integer)

If IsFormLoaded("Incoming") Then
MsgBox "Unable to open form." & vbCrLf & "Incoming form is open you must close it first."
Cancel = True
End If
End Sub

I put it on open event but there some errors.
Could you please look it.
 
Maybe you can help to me wth second problems?

I have posted it.

Thank you
 

Users who are viewing this thread

Back
Top Bottom