What's Wrong with this Code

M

MJatAflac

I am trying to create a simple(theoretically) procedure to open one form and
close another based on the variables passed to it. I've tried this:

Public Sub HandleForms(stDoc1 as string, stDoc2 as string)

Dim stOpen as string
Dim stClose as string

stOpen = stDoc1
stClose = stDoc2

doCmd.OpenForm stOpen

' If there is no form to close skip it
If stClose = "None" then
Exit Sub
End If

doCmd.Close acForm, stClose

End Sub

Then I call it Like this

HandleForms("frmPMMenu", "frmSignIn")

or like this

dim stDocOpen as string
dim stDocClose as string

stDocOpen = "frmPMMenu"
stDocClose = "frmSignIn"

HandleForms(stDocOpen, stDocClose)

In both scenarios I get a compile error in the call telling me that = is
expected.

I'm sure I've missed something very simple but I can't figure it out.

Thanks,

MPJ
 
D

Dirk Goldgar

MJatAflac said:
I am trying to create a simple(theoretically) procedure to open one
form and close another based on the variables passed to it. I've
tried this:

Public Sub HandleForms(stDoc1 as string, stDoc2 as string)

Dim stOpen as string
Dim stClose as string

stOpen = stDoc1
stClose = stDoc2

doCmd.OpenForm stOpen

' If there is no form to close skip it
If stClose = "None" then
Exit Sub
End If

doCmd.Close acForm, stClose

End Sub

Then I call it Like this

HandleForms("frmPMMenu", "frmSignIn")

or like this

dim stDocOpen as string
dim stDocClose as string

stDocOpen = "frmPMMenu"
stDocClose = "frmSignIn"

HandleForms(stDocOpen, stDocClose)

In both scenarios I get a compile error in the call telling me that =
is expected.

I'm sure I've missed something very simple but I can't figure it out.

Thanks,

MPJ

Your syntax for calling your Sub is incorrect. Use either of the two
formats below:

HandleForms stDocOpen, stDocClose

Call HandleForms(stDocOpen, stDocClose)
 

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