transfer a field using button

E

Emma

Hi I have a button which opens a form called Second Form; this form has a
client ID and the main form also has a client ID. When I create a new form,
it gives me a client ID however what I want is the client ID to be generated
from the first form. HEre's the code generated:

Private Sub Ctl1Y_Form_Click()
On Error GoTo Err_Ctl1Y_Form_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Second Form"

stLinkCriteria = "[Client ID]=" & "'" & Me![Client ID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Ctl1Y_Form_Click:
Exit Sub

Err_Ctl1Y_Form_Click:
MsgBox Err.Description
Resume Exit_Ctl1Y_Form_Click

End Sub

Can anyone show me how to get the second form's data based on client ID?
 
T

Tom Wickerath

Hi Emma,
Can anyone show me how to get the second form's data based on client ID?

The code that you posted uses the optional WhereCondition parameter. It
should result in opening the correct record, assuming the recordsource (table
or query) contains the same Client ID.
When I create a new form, it gives me a client ID however what I want
is the client ID to be generated from the first form.

It sounds to me like you are not creating a new form, but rather creating a
*new record* in "Second Form". I think you are wanting that new record to
have the same Client ID value as the calling form. If this is what you want,
you can use the optional OpenArgs parameter to pass the Client ID value.
Then, in Second Form's Open event, you can add code to determine if an
OpenArgs parameter was passed in, and if so, assign the value to that
appropriate control. You'd want to make sure to open Second Form in Add New
mode.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

Emma said:
Hi I have a button which opens a form called Second Form; this form has a
client ID and the main form also has a client ID. When I create a new form,
it gives me a client ID however what I want is the client ID to be generated
from the first form. HEre's the code generated:

Private Sub Ctl1Y_Form_Click()
On Error GoTo Err_Ctl1Y_Form_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Second Form"

stLinkCriteria = "[Client ID]=" & "'" & Me![Client ID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Ctl1Y_Form_Click:
Exit Sub

Err_Ctl1Y_Form_Click:
MsgBox Err.Description
Resume Exit_Ctl1Y_Form_Click

End Sub

Can anyone show me how to get the second form's data based on client ID?
 

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