Passing a date variable to anaother form

Jaco K

Registered User.
Local time
Today, 03:51
Joined
Aug 4, 2006
Messages
12
In form1 I've a command button to open form2.

Code in form1:

Private Sub button_Click()
On Error GoTo Err_button_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "form2"
stLinkCriteria = button.Caption
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_button_Click:
Exit Sub

Err_button_Click:
MsgBox Err.Description
Resume Exit_button_Click

End Sub

button.Caption contains a valid date value

In form2 I want to display the date in a label.

Code in form2:
Private Sub Form_Load()
Dim DatePassed As Date

DatePassed = CDate(Me.OpenArgs)
label.Caption = DatePassed
End Sub

On executing I get an error like "Invalid use of null value."

Who helps?
 
Im not a pro with passing variables. this can b done by using a code in form2 like

me.label.caption=forms!form1!button.caption
 
The criteria is use to filter records, not pass values from one form to another. Use the opening arg as suggested

DoCmd.OpenForm "form2", , , , , , Me.cmdButtonName.Caption

You need a few more commars to use the OpenArgs argument

Dave
 
Passing a date variable to another form

Mido and Oldsoftboss, thanks for reply.

Mido's suggestions works fine, but what if form2 is not only opened from form1 but also from multiple other forms?

I don't' understand Oldsoftboss' filter issue. Adding just 3 commars to the DoCmd line doesn't work.
 
Sorry, but I made a mistake. Adding 3 commars to the DoCmd line does work.
Thread can be closed.
 

Users who are viewing this thread

Back
Top Bottom