By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

Passing an Object (VBA Question)

P: n/a
Hi All,

I have the current Sub Procedure in a VBA Module.

-----------------------------------------------------------------------------------------------------------------------------
Sub openForm(formName As String, Optional varToSend As Object)
If varToSend Is Missing Then
DoCmd.openForm formName
Else
DoCmd.openForm formName, , , , , , varToSend
End If
End Sub
----------------------------------------------------------------------------------------------------------------------------
>From a button on "frmDash" I call: openForm("frmEmployeeAdjust") -
This Works Great

But when I call: openForm("frmEmployeeAdjust",empNo) - I get an Error
"Expected: = "

I know I could just write the code in the button and everything would
work, but I would like to write this simple function that I could call
anytime I needed to open a form. I always thought Object was generic
enough to contain any data type that exists, so I should be ok weather
I pass an Integer, String, Etc. Am I doing something blantantly wrong
here?
As always, Thanks in advance for all of your help!

Feb 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Remove your brackets after "OpenForm". VBA Compiler thinks you're
calling a function.

On Feb 28, 2:42 pm, "Matt" <mdw233...@yahoo.comwrote:
Hi All,

I have the current Sub Procedure in a VBA Module.

---------------------------------------------------------------------------*--------------------------------------------------
Sub openForm(formName As String, Optional varToSend As Object)
If varToSend Is Missing Then
DoCmd.openForm formName
Else
DoCmd.openForm formName, , , , , , varToSend
End If
End Sub
---------------------------------------------------------------------------*-------------------------------------------------
From a button on "frmDash" I call: openForm("frmEmployeeAdjust") -

This Works Great

But when I call: openForm("frmEmployeeAdjust",empNo) - I get an Error
"Expected: = "

I know I could just write the code in the button and everything would
work, but I would like to write this simple function that I could call
anytime I needed to open a form. I always thought Object was generic
enough to contain any data type that exists, so I should be ok weather
I pass an Integer, String, Etc. Am I doing something blantantly wrong
here?

As always, Thanks in advance for all of your help!

Feb 28 '07 #2

P: n/a
On Feb 28, 2:42 pm, "Matt" <mdw233...@yahoo.comwrote:
>
Hi All,
I have the current Sub Procedure in a VBA Module.
---------------------------------------------------------------------------*--------------------------------------------------
Sub openForm(formName As String, Optional varToSend As Object)
If varToSend Is Missing Then
DoCmd.openForm formName
Else
DoCmd.openForm formName, , , , , , varToSend
End If
End Sub
---------------------------------------------------------------------------*-------------------------------------------------
>From a button on "frmDash" I call: openForm("frmEmployeeAdjust") -
This Works Great
But when I call: openForm("frmEmployeeAdjust",empNo) - I get an Error
"Expected: = "
I know I could just write the code in the button and everything would
work, but I would like to write this simple function that I could call
anytime I needed to open a form. I always thought Object was generic
enough to contain any data type that exists, so I should be ok weather
I pass an Integer, String, Etc. Am I doing something blantantly wrong
here?
As always, Thanks in advance for all of your help!
On Feb 28, 3:24 pm, "Jason Lepack" <jlep...@gmail.comwrote:
Remove your brackets after "OpenForm". VBA Compiler thinks you're
calling a function.
"Use of Parentheses in Procedure Calls:

It is sometimes confusing to determine when to use, or not to use,
parentheses ( ) to enclose argument lists with a VBA subroutine or
function.

For example, subroutines or functions that do not receive arguments in
VBA do not require parentheses. Otherwise, parentheses are required in
the declaration. When calling a subroutine, you can either call the
subroutine directly by name, or you may call it by using the Call
statement. When calling a subroutine directly, you never use
parentheses. When using the Call statement to call a function that
takes arguments, you must use parentheses. When using the Call
statement to call a function that does not take arguments, you do not
use parentheses."

<whew>

Feb 28 '07 #3

P: n/a
On Feb 28, 3:53 pm, "robert.waters" <robert.wat...@gmail.comwrote:
On Feb 28, 2:42 pm, "Matt" <mdw233...@yahoo.comwrote:
Hi All,
I have the current Sub Procedure in a VBA Module.
---------------------------------------------------------------------------**--------------------------------------------------
Sub openForm(formName As String, Optional varToSend As Object)
If varToSend Is Missing Then
DoCmd.openForm formName
Else
DoCmd.openForm formName, , , , , , varToSend
End If
End Sub
---------------------------------------------------------------------------**-------------------------------------------------
From a button on "frmDash" I call: openForm("frmEmployeeAdjust") -
This Works Great
But when I call: openForm("frmEmployeeAdjust",empNo) - I get an Error
"Expected: = "
I know I could just write the code in the button and everything would
work, but I would like to write this simple function that I could call
anytime I needed to open a form. I always thought Object was generic
enough to contain any data type that exists, so I should be ok weather
I pass an Integer, String, Etc. Am I doing something blantantly wrong
here?
As always, Thanks in advance for all of your help!

On Feb 28, 3:24 pm, "Jason Lepack" <jlep...@gmail.comwrote:
Remove your brackets after "OpenForm". VBA Compiler thinks you're
calling a function.

"Use of Parentheses in Procedure Calls:

It is sometimes confusing to determine when to use, or not to use,
parentheses ( ) to enclose argument lists with a VBA subroutine or
function.

For example, subroutines or functions that do not receive arguments in
VBA do not require parentheses. Otherwise, parentheses are required in
the declaration. When calling a subroutine, you can either call the
subroutine directly by name, or you may call it by using the Call
statement. When calling a subroutine directly, you never use
parentheses. When using the Call statement to call a function that
takes arguments, you must use parentheses. When using the Call
statement to call a function that does not take arguments, you do not
use parentheses."

<whew>- Hide quoted text -

- Show quoted text -
Whew is right ... but it helped a ton. Thanks to both of you!!!!!

Feb 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.