Copying a field from one form to another by code.

F

fitzy

I have a form called frmClients with a field ClientID.
I have another form called frmCoachingSessions also with a field
ClientID

I would like to place a command button on the frmClient and when it is
clicked I want it to open frmCoachingSessions and copy the ClientID
accrossfrom one form to the next. The frmCoachingSessions would be in
adding a new record mode.

Any help with this would be appreciated.
 
J

John W. Vinson

I have a form called frmClients with a field ClientID.
I have another form called frmCoachingSessions also with a field
ClientID

I would like to place a command button on the frmClient and when it is
clicked I want it to open frmCoachingSessions and copy the ClientID
accrossfrom one form to the next. The frmCoachingSessions would be in
adding a new record mode.

Any help with this would be appreciated.

By far the simplest method to do this involves no code at all - just make
frmCoachingSessions a Subform of frmClient, and use ClientID as the
master/child link field.

If you have some good reason not to do this, you can pass the ClientID in the
OpenArgs argument of the OpenForm method. Edit the (wizard-generated?) command
button code to something resembling

strDocument = "frmCoachingSessions"
DoCmd.OpenForm strDocument, OpenArgs:= Me!ClientID


and in the Open event of frmCoachingSessions use code like

Private Sub Form_Open(Cancel as Integer)
If Len(Me.OpenArgs & "") > 0 Then
Me!ClientID.DefaultValue = """" & Me.OpenArgs & """"
End If
End Sub
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
F

fitzy

By far the simplest method to do this involves no code at all - just make
frmCoachingSessions a Subform of frmClient, and use ClientID as the
master/child link field.

If you have some good reason not to do this, you can pass the ClientID inthe
OpenArgs argument of the OpenForm method. Edit the (wizard-generated?) command
button code to something resembling

strDocument = "frmCoachingSessions"
DoCmd.OpenForm strDocument, OpenArgs:= Me!ClientID

and in the Open event of frmCoachingSessions use code like

Private Sub Form_Open(Cancel as Integer)
If Len(Me.OpenArgs & "") > 0 Then
   Me!ClientID.DefaultValue = """" & Me.OpenArgs & """"
End If
End Sub
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com

Thanks John,

I hadn't thought about the subform. That is a great suggestion. Thanks
for your advice.

Brian
 

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

Top