0
votes

I have a form from which I can Access 2 another forms. I can do that by clicking into selected record. What I want to do is prevent user to open second form in any different record that first form is allready opened. So far I have tried this (in Current event of 1st form - let me call It Main form):

If CurrentProject.AllForms("MySecondForm").IsLoaded And CurrentProject.AllForms("MyThirdForm").IsLoaded Then
   If Forms![MySecondForm].Form![ID] = Forms![MyThirdForm].Form![ID] Then
        'do nothing

   Else

   ...

   MsgBox "Error. You cannot open both forms in different records !"

   End If

End If

Any ideas on which event I need to use code, and how to prevent that ?

1

1 Answers

0
votes

Solved, here is what I had to do:

  If Not CurrentProject.AllForms("MySecondForm").IsLoaded Then

      DoCmd.OpenForm "MyThirdForm", , , "ID=" & Forms![MainForm].Form![ID]

   ElseIf CurrentProject.AllForms("MySecondForm").IsLoaded Then

      DoCmd.OpenForm "MyThirdForm", , , "ID=" & Forms![MainForm].Form![ID]

      If Forms![MyThirdForm].Form![ID] = Forms![MySecondForm].Form![ID] Then

              'Do nothing

      Else

      MsgBox "Error. You cannot open both forms in different records !", vbCritical
              DoCmd.Close acForm, "MyThirdform"
              Exit Sub

      End If

   End If

If anybody has solution that would prevent opening form, please post. This solution opens form, checks record ID's and then closes form, which is not exactly perfect.