Open a form with previous forms ID

Elmobram22

Registered User.
Local time
Today, 21:22
Joined
Jul 12, 2013
Messages
165
Hi,

I am trying to have cascading forms running on my database. The first form adds a new staff member. When you press the next button this happens...

Private Sub Command12_Click()
DoCmd.Close
DoCmd.OpenForm "Frm2"
End Sub

But I want it to open Frm2 using the ID from the previous form. The stumbling block for me is I close the first form before opening the next so I cant pass the ID across. Is there an easy fix for this?

Cheers,

Paul
 
Try this:

Private Sub Command12_Click()
On Error GoTo Err_Command12_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = " Frm2 "

stLinkCriteria = "[ID]=" & "" & Me![ID] & ""
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me![ID]
DoCmd.Close acForm, " Frm1"

Exit_Command12_Click:
Exit Sub

Err_Command12_Click:
MsgBox Err.Description
Resume Exit_Command12_Click
End Sub

and add this to Frm2 to get ID from Frm1

Private Sub Form_Load()
If IsNull(Me!ID) And Not IsNull(Me.OpenArgs) Then
Me!ID = Me.OpenArgs
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom