Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transfer ID value from one form to another form 1

Status
Not open for further replies.

Phil4tektips

Technical User
Jul 18, 2005
89
GB
This should be simple, and I bet it is!

I've been trying for a while now to take the value from an ID field across with me to another form and input it into a text box.

I only want this to happen on a particular button click, I have therefore used Openargs on in the code of the form.

The code on Click event of the button:

Private Sub Print_Risk_A4_Format_Click()
On Error GoTo Err_Print_Risk_A4_Format_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim j As Integer
j = [ID Number]
stDocName = "View Full Risk form"
DoCmd.OpenForm stDocName, , , , , , "J"


Exit_Print_Risk_A4_Format_Click:
Exit Sub

Err_Print_Risk_A4_Format_Click:
MsgBox Err.Description
Resume Exit_Print_Risk_A4_Format_Click

End Sub

This is the code for the form upon Opening:

Private Sub Form_Open(Cancel As Integer)
If Me.OpenArgs = "J" Then
[ID Number] = j
Else
' do nothing
End If
End Sub

The two fields are called the same name, but are obviously on different forms.

The ID Number on the first form is an Autonumber.

Can anyone help?

Thanks.

-Phil4tektips-
 
Replace this:
DoCmd.OpenForm stDocName, , , , , , "J"
By this:
DoCmd.OpenForm stDocName, , , , , , "J=" & j
and this:
If Me.OpenArgs = "J" Then
[ID Number] = j
Else
' do nothing
End If
By this:
If Me.OpenArgs Like "J=*" Then
[ID Number] = Val(Mid(Me.OpenArgs, 3))
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Excellent.

Worked exactly how I need it to!

Prompt and sound advice.

-Phil4tektips-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top