Set its Modal property to Yes.
I'm having the same problem that I encountered with your first method.
Here's the problem in a nutshell: Let's say that I have three forms-
Form1, Form2, and Form3. On Form2, the Modal Property is set to 'Yes.'
On Form1, I have a button that opens Form2, using the following code:
Private Sub OpenForm2_Click()
DoCmd.OpenForm "Form1"
End Sub
Form2 acts basically like a filter for Form3. After the user selects
an ID from a list box on Form2, they click a button, marked OK, and it
runs the following code:
Private Sub OK_Click()
Dim str As String
str = Me.ID
On Error GoTo Err_OK_Click
DoCmd.OpenForm "Form3"
Forms!Form3!ID.SetFocus
DoCmd.FindRecord str
DoCmd.Close acForm, "Form2"
Exit_OK_Click:
Exit Sub
Err_OK_Click:
MsgBox Err.Description
GoTo Exit_OK_Click
End Sub
Now normally, this has worked just fine. However, when this code is
run with the Modal Property of Form2 set to Yes, it opens Form3 behind
Form1.
Now I've tried putting in the following line of code at the end of the
sequence to correct for this issue and it works fine for the most
part:
Forms!Form3.SetFocus
However, on Form3, I have a button that can be used to open Form2, in
case the user decides to select a different advisor. If I click on
this button, I get an error message that says "A macro set to one of
the current field's properties failed because of an error in a
FindRecord action argument." If I take this line of code back out of
Form2, though, the button works just fine from Form3.
It's funny how complicated something that seems relatively simple can
ultimately turn out to be.
