N
night_writer
I am trying to pass some arguments from one form to another. Sometimes
it works, and sometimes it doesn't.
On the originating form, this is my code:
~~~~~
Dim stDocName As String
Dim stLinkCriteria As String
Dim strOpenArgs As String
If IsNull(Forms!frmForms!FormID) Then
MsgBox "You must have a form ID before adding states."
Exit Sub
End If
strOpenArgs = Me.FormID & "|" & Me.strTitle & "|" &
Me.strFormNumber
MsgBox strOpenArgs
stDocName = "frmMultiStateEntry"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , strOpenArgs
~~~~~
The MsgBox strOpenArgs shows that I do indeed have a string each and
every time.
My code in the receiving form is:
~~~~~
Private Sub Form_Open(Cancel As Integer)
Dim varFormIdent As Variant
If Not IsNull(OpenArgs) Then
varFormIdent = Split(OpenArgs, "|")
Me.FormID = varFormIdent(0)
Me.strFormTitle = varFormIdent(1)
Me.strFormNumber = varFormIdent(2)
Else
MsgBox "You can't add states until you have a form ID."
End If
End Sub
~~~~~~
Sometimes I get the error message even though my MsgBox on leaving the
original form shows that strOpenArgs exists and hold the data I
expect.
Sometimes I don't have strFormNumber, but that doesn't seem to make
any difference, since sometimes it works. I can't really figure out
any consistancy in when the second form will open correctly. It error
did seem to occur more often when I had just started a new record in
the first form, however it does occur even on existing records.
I would appreciate any thoughts or ideas on what could be causing this
problem and how I could fix it.
Alice
it works, and sometimes it doesn't.
On the originating form, this is my code:
~~~~~
Dim stDocName As String
Dim stLinkCriteria As String
Dim strOpenArgs As String
If IsNull(Forms!frmForms!FormID) Then
MsgBox "You must have a form ID before adding states."
Exit Sub
End If
strOpenArgs = Me.FormID & "|" & Me.strTitle & "|" &
Me.strFormNumber
MsgBox strOpenArgs
stDocName = "frmMultiStateEntry"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , strOpenArgs
~~~~~
The MsgBox strOpenArgs shows that I do indeed have a string each and
every time.
My code in the receiving form is:
~~~~~
Private Sub Form_Open(Cancel As Integer)
Dim varFormIdent As Variant
If Not IsNull(OpenArgs) Then
varFormIdent = Split(OpenArgs, "|")
Me.FormID = varFormIdent(0)
Me.strFormTitle = varFormIdent(1)
Me.strFormNumber = varFormIdent(2)
Else
MsgBox "You can't add states until you have a form ID."
End If
End Sub
~~~~~~
Sometimes I get the error message even though my MsgBox on leaving the
original form shows that strOpenArgs exists and hold the data I
expect.
Sometimes I don't have strFormNumber, but that doesn't seem to make
any difference, since sometimes it works. I can't really figure out
any consistancy in when the second form will open correctly. It error
did seem to occur more often when I had just started a new record in
the first form, however it does occur even on existing records.
I would appreciate any thoughts or ideas on what could be causing this
problem and how I could fix it.
Alice