Reference the form that opened the current form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have one form used for editing, that can be opened by two other forms.
Since this is not a parent child relationship, is there a way to reference
the form that opened the active form? Example of what I am searching for:

If opened by frm1 Then
Me.ID = Forms![frm1]![ID]
Else
If opened by frm2 Then
Me.ID = Forms![frm1]![ID]
End If
End If

Thank you in advance!
Renee
 
Typo, sorry, should be:
If opened by frm1 Then
Me.ID = Forms![frm1]![ID]
Else
If opened by frm2 Then
Me.ID = Forms![frm2]![ID]
End If
End If

Renee said:
I have one form used for editing, that can be opened by two other forms.
Since this is not a parent child relationship, is there a way to reference
the form that opened the active form? Example of what I am searching for:

If opened by frm1 Then
Me.ID = Forms![frm1]![ID]
Else
If opened by frm2 Then
Me.ID = Forms![frm1]![ID]
End If
End If

Thank you in advance!
Renee
 
Renee said:
I have one form used for editing, that can be opened by two other forms.
Since this is not a parent child relationship, is there a way to reference
the form that opened the active form? Example of what I am searching for:

If opened by frm1 Then
Me.ID = Forms![frm1]![ID]
Else
If opened by frm2 Then
Me.ID = Forms![frm1]![ID]
End If
End If

Thank you in advance!
Renee

On the assumption that you are opening the form using OpenForm, use the
OpenArgs argument to pass in either the name of the opening form or (better)
the value of ID.
 
Typo, sorry, should be:
If opened by frm1 Then
Me.ID = Forms![frm1]![ID]
Else
If opened by frm2 Then
Me.ID = Forms![frm2]![ID]
End If
End If

Renee said:
I have one form used for editing, that can be opened by two other forms.
Since this is not a parent child relationship, is there a way to reference
the form that opened the active form? Example of what I am searching for:

If opened by frm1 Then
Me.ID = Forms![frm1]![ID]
Else
If opened by frm2 Then
Me.ID = Forms![frm1]![ID]
End If
End If

Thank you in advance!
Renee

Use the OpenArgs argument when you open the form:
DoCmd.OpenForm "FormName", , , , , , Me.Name

Then in the "FormName" Load event:
If Me.OpenArgs = "Form1" Then
Me.ID = Forms![form1]![ID]
Elseif Me.OpenArgs = "Form2" Then
Me.ID = Forms![form2]![ID]
Else
' Do something else
End If

Why not just pass the form's [ID] field value instead of the name of
the form?

DoCmd.OpenForm "FormName", , , , , , Me![ID]

Then in the "FormName" Load event:

If Not IsNull(Me.OpenArgs) then
Me!ID = Me.OpenArgs
End If
 
If you want to pass the calling form's name, and you're pulling the same
field (ID) from it, you don't need to use the if..then clause:
Me.ID=Forms(Me.OpenArgs)![ID]
this way, it won't matter what the calling form's name is. Sometimes I end
up changing form names, so I try to avoid hard-coding a name if possible.

As mentioned before, if all you're trying to do is come up with the value in
the ID field, then just pass that as the OpenArg.

fredg said:
Typo, sorry, should be:
If opened by frm1 Then
Me.ID = Forms![frm1]![ID]
Else
If opened by frm2 Then
Me.ID = Forms![frm2]![ID]
End If
End If

Renee said:
I have one form used for editing, that can be opened by two other forms.
Since this is not a parent child relationship, is there a way to
reference
the form that opened the active form? Example of what I am searching
for:

If opened by frm1 Then
Me.ID = Forms![frm1]![ID]
Else
If opened by frm2 Then
Me.ID = Forms![frm1]![ID]
End If
End If

Thank you in advance!
Renee

Use the OpenArgs argument when you open the form:
DoCmd.OpenForm "FormName", , , , , , Me.Name

Then in the "FormName" Load event:
If Me.OpenArgs = "Form1" Then
Me.ID = Forms![form1]![ID]
Elseif Me.OpenArgs = "Form2" Then
Me.ID = Forms![form2]![ID]
Else
' Do something else
End If

Why not just pass the form's [ID] field value instead of the name of
the form?

DoCmd.OpenForm "FormName", , , , , , Me![ID]

Then in the "FormName" Load event:

If Not IsNull(Me.OpenArgs) then
Me!ID = Me.OpenArgs
End If
 
Thank you much, that worked perfectly!

Have a great weekend,
Renee

fredg said:
Typo, sorry, should be:
If opened by frm1 Then
Me.ID = Forms![frm1]![ID]
Else
If opened by frm2 Then
Me.ID = Forms![frm2]![ID]
End If
End If

Renee said:
I have one form used for editing, that can be opened by two other forms.
Since this is not a parent child relationship, is there a way to reference
the form that opened the active form? Example of what I am searching for:

If opened by frm1 Then
Me.ID = Forms![frm1]![ID]
Else
If opened by frm2 Then
Me.ID = Forms![frm1]![ID]
End If
End If

Thank you in advance!
Renee

Use the OpenArgs argument when you open the form:
DoCmd.OpenForm "FormName", , , , , , Me.Name

Then in the "FormName" Load event:
If Me.OpenArgs = "Form1" Then
Me.ID = Forms![form1]![ID]
Elseif Me.OpenArgs = "Form2" Then
Me.ID = Forms![form2]![ID]
Else
' Do something else
End If

Why not just pass the form's [ID] field value instead of the name of
the form?

DoCmd.OpenForm "FormName", , , , , , Me![ID]

Then in the "FormName" Load event:

If Not IsNull(Me.OpenArgs) then
Me!ID = Me.OpenArgs
End If
 
Back
Top