OpenArgs Questions

R

Rose

I know how to link a sub form within a Main Form by creating a child and
parent field with the same ID. However, I am having a problem creating a
link with a command button from one form to another and forcing it to take
the same ClientID. It has been suggested to Pass the ID to the other form
using the OpenArgs argument of the OpenForm method. I am not sure how this
works, can anyone break it down in simplistic terms. Thanks, Rose
 
R

Randy

Rose, I am not an expert, but the way I would do it is when you click a
command button in the 'calling form', I would execute the Docmd.openform and
pass the calling form ID as a parameter to be passed to the form you are
opening. For example, DoCmd.OpenForm "Password", acNormal, , , acFormEdit,
acDialog, ID (where ID is the ID you are wanting to pass by way of OpenArgs
to the form you are opening). Obviously, you may wish to use difference
parameters than the ones I used in my example EXCEPT you will want the last
parameter to be the ID since that is the OpenArgs parameter. When the new
form opens, you can easily retrieve the ID in the Form_Open event or the
Form_Load event by using the Me.OpenArgs property. I would store this to a
variable. There are several ways at this point to position yourself in the
underlying recordset of the new form you have opened. You probably know how
to do that already. I hope this helps and I apologize if some of the terms I
used were not 'official Access language.' Randy
 
J

John W. Vinson

I know how to link a sub form within a Main Form by creating a child and
parent field with the same ID. However, I am having a problem creating a
link with a command button from one form to another and forcing it to take
the same ClientID. It has been suggested to Pass the ID to the other form
using the OpenArgs argument of the OpenForm method. I am not sure how this
works, can anyone break it down in simplistic terms. Thanks, Rose

Well... if you're using the OpenForm method, it is *NOT* a Subform, and the
forms will not be "linked" in the way that subforms are.

What you can do involves code in both the calling form and in the called form.
For instance, you might open the form with code like

DoCmd.OpenForm "frmMySecondForm", _
WhereCondition:="[ClientID] = " & Me!ClientID, _
OpenArgs = Me!ClientID

This will open the form displaying only those records (if any) for the calling
form's value of ClientID. In frmMySecondForm's Open event you would put code
like:

Private Sub Form_Open(Cancel as Integer)
If Me.OpenArgs & "" <> "" Then ' if there was an OpenArgs passed...
Me!txtClientID.DefaultValue = Me.OpenArgs
' set the default value of the bound control txtClientID to its value
End If
End Sub


John W. Vinson [MVP]
 
R

Randy

I thought she was wanting to open an entirely new form. Didn't think she was
trying to pass a value back and forth between the subform and the main form.
--
Randy


John W. Vinson said:
I know how to link a sub form within a Main Form by creating a child and
parent field with the same ID. However, I am having a problem creating a
link with a command button from one form to another and forcing it to take
the same ClientID. It has been suggested to Pass the ID to the other form
using the OpenArgs argument of the OpenForm method. I am not sure how this
works, can anyone break it down in simplistic terms. Thanks, Rose

Well... if you're using the OpenForm method, it is *NOT* a Subform, and the
forms will not be "linked" in the way that subforms are.

What you can do involves code in both the calling form and in the called form.
For instance, you might open the form with code like

DoCmd.OpenForm "frmMySecondForm", _
WhereCondition:="[ClientID] = " & Me!ClientID, _
OpenArgs = Me!ClientID

This will open the form displaying only those records (if any) for the calling
form's value of ClientID. In frmMySecondForm's Open event you would put code
like:

Private Sub Form_Open(Cancel as Integer)
If Me.OpenArgs & "" <> "" Then ' if there was an OpenArgs passed...
Me!txtClientID.DefaultValue = Me.OpenArgs
' set the default value of the bound control txtClientID to its value
End If
End Sub


John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Link Form 1
Access OpenArgs in Access 2010 failing 0
Open the same form 2
Use of OpenArgs 5
Form with Tab Control and OpenArgs 7
Incomprehensible OpenArgs behavior 2
Form Corruption 2
OpenArgs yawn yawn 9

Top