erratic OpenArgs behavior

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
 
D

David-W-Fenton

m:
~~~~~
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
~~~~~~

It's not clear what you're assigning, but if these are controls, you
should be doing this in OnLoad, instead of OnOpen, because controls
are not completely initialized until after OnOpen completes.

I don't expect this to fix your problem, though.

It seems to me that the problem is with the data you're passing in
that you don't seem to have values in all cases. If Me.strFormTitle
is a string variable, then if VarFormIdent(1) returns Null, it will
cause a problem. But I don't think it will, since you were splitting
a string variable, so it should return a zero-length string. If, on
the other hand, Me.strFormTitle is a control bound to a field that
prohibits ZLS, then you'd have a problem.

I'd put a break point on the line after the Split() and see what is
getting assigned to the array. Also, I'm not sure there's any reason
to define the array as variant -- seems to me that String should be
sufficient, since the array is being created from data in a string
variable.
 
N

night_writer

m:









It's not clear what you're assigning, but if these are controls, you
should be doing this in OnLoad, instead of OnOpen, because controls
are not completely initialized until after OnOpen completes.

I don't expect this to fix your problem, though.

It seems to me that the problem is with the data you're passing in
that you don't seem to have values in all cases. If Me.strFormTitle
is a string variable, then if VarFormIdent(1) returns Null, it will
cause a problem. But I don't think it will, since you were splitting
a string variable, so it should return a zero-length string. If, on
the other hand, Me.strFormTitle is a control bound to a field that
prohibits ZLS, then you'd have a problem.

I'd put a break point on the line after the Split() and see what is
getting assigned to the array. Also, I'm not sure there's any reason
to define the array as variant -- seems to me that String should be
sufficient, since the array is being created from data in a string
variable.

--
David W. Fenton                  http://www.dfenton.com/
contact via website only    http://www.dfenton.com/DFA/- Hide quoted text -

- Show quoted text -


Thank you very much! I think you identified the problem with your
first comment. I neglected to mention that any time I got the error
message on opening the new form, the form would continue to open
(after I clicked OK to the error message), but without the controls
filled in with the data I was trying to pass. Then, I would close the
form and open it again, and the second time, it would open correctly.

Is it possible that the loading of the form the first time left some
kind of residual initialization that made it possible to load it
again, immediately after? Anyway, I've done a few test runs with the
subroutine in the OnLoad event, and so far, no problems. But that's
one of the annoying things about stuff that doesn't happen all the
time...only time will tell!

As to the Varient data type for my array, I've never used arrays
before and was working off a sample. I didn't realize anything else
was an option. I will now fix this to a data type that takes up less
space :) The form I'm opening isn't bound to an underlying table. The
only thing I really need of the data I'm passing is the FormID, which
I will use in an SQL statement later. The other parts are only to help
the user stay oriented.

Thank you again for your help!

Alice
 

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