Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / February 2007

Tip: Looking for answers? Try searching our database.

Passing an Object (VBA Question)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matt - 28 Feb 2007 19:43 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.