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!
Albert D. Kallal - 28 Feb 2007 20:35 GMT
OpenArgs MUST be a string, it can't be object....
so, you need:
Sub openForm(formName As String, Optional varToSend As string)
varToSend since it is to be passed a arugment, MUST BE simple string
var....
if varToSend is a number, or string, then ms-access can/will cast the number
as a string for you..but, it not the acutal object, but simple string
var...

Signature
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com
storrboy - 28 Feb 2007 20:39 GMT
> Hi All,
>
[quoted text clipped - 25 lines]
>
> As always, Thanks in advance for all of your help!
Object is rather generic but it's not the best thing to use for known
objects.
If the variable represents a control use As Control, if it's just data
but of an unknown type use Variant. Basically always use the most
appropriate variable type.
Second the manner in which you check if the variable was passed is
incorrect. It should read...
If IsMissing(varToSend) Then