Open form with arguments - invalid use of NUL:

A

Alan T

In main form:
Private Sub btnOpen_Click()
DoCmd.OpenForm "frmEmployee", acNormal, , , acFormAdd, acWindowNormal,
"Alan"
End Sub

In second form:
Private Sub Form_Open(Cancel As Integer)
Dim empName As String
empName = Forms!frmEmployee.OpenArgs <-- runt time error
If Len(empName ) > 0 Then
MsgBox empName
Else
MsgBox "null"
End If
End Sub

The runtime error was:
Invalid use of NULL
 
A

Andy Hull

Hi Alan

From your post it looks like your OpenArgs parameter ("Alan") is on a
separate line to the rest of the code.

It needs to be on the same line in the VBA editor.

Sometimes posts can look confusing because of the word wrapping in the post.

Hope this helps

Andy Hull
 
A

Alan T

Hi,

1) My original post has been wrapped. The "Alan" is on the same line in my
OpenForm method.
2) I tried Me.OpenArgs but no luck, still get the same error.
 
K

Keith Wilby

Alan T said:
Hi,

1) My original post has been wrapped. The "Alan" is on the same line in my
OpenForm method.
2) I tried Me.OpenArgs but no luck, still get the same error.

Then for some reason your OpenArg *is* null. Try stepping through the code
at run time to find when OpenArgs loses its value.

Keith.
 
A

Andy Hull

Hi again Alan

As Keith has said it would seem that the OpenArgs is really Null and I would
do as he suggests looking at the value of Me.OpenArgs as you step through
each line of code.

But, there doesn't look like there is any opportunity for the OpenArgs to
lose it's value of "Alan".

I just need to check one thing with you. You said "In second form:" Is this
second form the form named frmEmployee or a different form altogether?

You are opening frmEmployee with an OpenArgs parameter of "Alan" so you have
to use Me.OpenArgs in the open event of frmEmployee (not any other form).

Sorry if this is obvious but I'm clutching at straws as I can't see where
else it could be going wrong!

Regards

Andy Hull
 
A

Alan T

Hi,

Yes, I specified the frmEmployee is correct.
I also set the button's visible property using the frmEmployee right after
the OpenForm command.
 
M

missinglinq via AccessMonster.com

Having grown tired of watching war movies and listening to martial music this
(in the USA) holiday weekend, I took the time to set up a db to try and
duplicate Alan's problem. Using his original code(and BTW, Me.OpenArgs and
Forms!frmEmployee.OpenArgs can both be used here) I could only reproduce the
error, as has been suggested, when OpenArgs actually is null!

I've no idea where "Alan" is disappearing, but anytime there's code
referencing OpenArgs in the opening/loading of a form, there should be a
check to assure that it is not Null! Something like this would cover the
situation here:

Private Sub Form_Open(Cancel As Integer)
Dim empName As String

'Only assign OpenArgs to empName if it's not Null
If Not IsNull(Me.OpenArgs) Then
empName = Me.OpenArgs
End If

If Len(empName) > 0 Then
MsgBox empName
Else
MsgBox "null"
End If
End Sub

BTW, when referring to a form, within it's own code module, it's probably
good policy to use

Me.

rather than, as you would here

Forms!frmEmployee.

for the simple reason that you're less likely to make a typo error.
 

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