Problem with a Public Sub

G

Guest

I am having a problem with the following, when I click on the button
command3, the form that is opened has a FORM_OPEN command that uses openargs,
but I get an invalid use of NULL, and I think that it is from not recognizing
the openargs. What do I need to differently. Since I have several buttons
that all open the same form, I would like to have the public sub.

Thanks

Public Sub OPENFRM()

DoCmd.OpenForm "SFRMCA_SELECTAPPS", acNormal, , , , , stdocname
Forms!SFRMCA_SELECTAPPS!Command11.Visible = True

End Sub

Private Sub Command3_Click()
On Error GoTo Err_Command3_Click

Dim stdocname As String

stdocname = "frmCA_ADD_IDEA0"
Call OPENFRM

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click

End Sub
 
J

John Welch

You declared the variable stdocname in the click event procedure of your
button, so that's the only place it exists. You need to pass that value to
your OPENFRM routine. So, instead of
Public Sub OPENFRM(),
you should say:
Public Sub OPENFRM( stdocname as string) , or Public Sub OPENFRM ( stArgs as
string) (You can call the value received anything you want)
to tell the function to expect a string to be passed to it. Then you can use
stdocname or stArgs (or whatever you call it) in your OPENFRM routine.
In your button click routine, to call OPENFRM , you would say:
OPENFRM (stdocname)

Note that you don't have to make a sub public if it lives in the same place
(form module) as the buttons that call it. It only needs to be public if
code from some other place needs to call it. So you might be better off
saying
Private Sub OPENFRM( stdocname as string)

hope this helps
 

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