473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Cannot pass a form object to a module

I have one module where I would like to launch 2 different forms (that
do exist), based on a form object and string that is passed into it.
(prmTable is a string, not a table object simply because prmTable is
only used in the form's caption)
(I know I could put this code behind a form object, but my goal is to
modularize this code somewhat and get this technique down so that I
can import this code to other applications in the future where I need
to use one code module to pass in different forms)

I have the following code in a VBA module object called mod_UTIL:

<begin code>
Private Sub ViewOutputData(prmForm As Form, prmTable As String)
DoCmd.OpenForm prmForm, acFormDS 'open the form in Datasheet view
prmForm.Caption = "Data Output from " & prmTable
End Sub
<end code>

Here, is where the above module is called:
<begin code>
Private Sub cmdW1Data_Click()
ViewOutputData Forms!frmW1DataOut, "tblW1DataOut"
End Sub
<end code>

....in another module:
Private Sub cmdW2Data_Click()
ViewOutputData Forms!frmW2DataOut, "tblW2Dataout"
End Sub

To try and pass in the form object, I have tried various flavors for
this trying to get this to work:

ViewOutputData Forms!frmW1DataOut, "tblW1Dataout" yields:
"Access cannot find the form frmW2DataOut"

ViewOutputData "Forms!frmW1DataOut", "tblW1Dataout" yields:
"type mismatch error"

ViewOutputData [Forms!frmW1DataOut], "tblW1Dataout" yields:
"access can't find the field "|" referred in your expression."

ViewOutputData frmW1DataOut, "tblW1Dataout" yields:
"By Ref Argumant type mismatch'

What is still not correct with my code? Any assistance is very much
appreciated.

Thank you.

Jul 16 '07 #1
4 5191
On Mon, 16 Jul 2007 08:07:44 -0700, rl*********@yahoo.com wrote:

See comments in-line.
-Tom.
>I have one module where I would like to launch 2 different forms (that
do exist), based on a form object and string that is passed into it.
(prmTable is a string, not a table object simply because prmTable is
only used in the form's caption)
(I know I could put this code behind a form object, but my goal is to
modularize this code somewhat and get this technique down so that I
can import this code to other applications in the future where I need
to use one code module to pass in different forms)

I have the following code in a VBA module object called mod_UTIL:

<begin code>
Private Sub ViewOutputData(prmForm As Form, prmTable As String)
DoCmd.OpenForm prmForm, acFormDS 'open the form in Datasheet view
prmForm.Caption = "Data Output from " & prmTable
End Sub
<end code>

Here, is where the above module is called:
<begin code>
Private Sub cmdW1Data_Click()
ViewOutputData Forms!frmW1DataOut, "tblW1DataOut"
End Sub
<end code>

...in another module:
Private Sub cmdW2Data_Click()
ViewOutputData Forms!frmW2DataOut, "tblW2Dataout"
End Sub

To try and pass in the form object, I have tried various flavors for
this trying to get this to work:

ViewOutputData Forms!frmW1DataOut, "tblW1Dataout" yields:
"Access cannot find the form frmW2DataOut"
No, that is illogical. Check your code.
This is a correct calling syntax.
Alternative: ViewOutputData Me, Me.Caption
Of course the referenced form must be open, otherwise it is not part
of the Forms collection.
>
ViewOutputData "Forms!frmW1DataOut", "tblW1Dataout" yields:
"type mismatch error"
Of course. If your sub expects a form object, you can't pass a string
variable.
>
ViewOutputData [Forms!frmW1DataOut], "tblW1Dataout" yields:
"access can't find the field "|" referred in your expression."
Illegal syntax.
>
ViewOutputData frmW1DataOut, "tblW1Dataout" yields:
"By Ref Argumant type mismatch'
This works in my test db. You *may* be able to fix this by changing
to:
Private Sub ViewOutputData(ByVal prmForm As Form, ByVal prmTable As
String)
>
What is still not correct with my code? Any assistance is very much
appreciated.

Thank you.
Jul 17 '07 #2
Hi there,

The problem is with this function:

Private Sub ViewOutputData(prmForm As Form, prmTable As String)
DoCmd.OpenForm prmForm, acFormDS 'open the form in Datasheet
view
prmForm.Caption = "Data Output from " & prmTable
End Sub

More specifically, it is with DoCmd.OpenForm. The first argument to
this method is the NAME of the form (as a string) to open, not a form
object. Here is the corrected version:

<begin code>
Private Sub ViewOutputData(strForm As String, prmTable As String)
DoCmd.OpenForm strForm, acFormDS 'open the form in Datasheet
view
Forms(strForm).Caption = "Data Output from " & prmTable
End Sub
<end code>

You would call it as such:
Private Sub cmdW2Data_Click()
ViewOutputData "frmW2DataOut", "tblW2Dataout"
End Sub

You can only reference the form object if the form is already open.

I hope this helps!

Jul 18 '07 #3
Tom,
This worked in a test db...thank you. I appreciate it.

Jul 19 '07 #4
This worked great...thanks! ...very helpful here.
I do get confused sometimes when passing strings vs actual object
names.
Your example here provided clarification.

Jul 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gerhard Pretorius | last post by:
ON Win 2003 IIS6, Since yesterday, (12 Aug 2003) for some strange reason, (after installing WindowsServer2003-KB823980-x86-ENU.exe) I cannot pass the Request object to to VB COM DLL. I have...
11
by: Vanessa | last post by:
Hi, I would like to know whether there's any way for me to pass an object by reference to another form? Regards Vanessa
7
by: NetCoder | last post by:
Hi to all, I have made a script that uses both JavaScript and PHP. The script has a form and when it is submitted, a JavaScript confirmation box appears, asking the user to confirm their action....
5
by: Simone | last post by:
Hello I am really confused on this. I have a button that calls a module. Sub verifyUser(frmEntry As Form) This module does a few things then it opens a form. I am passing a variable as...
7
by: allyn44 | last post by:
Hello--I have the code below attached to a command button--it opens an error log form: DoCmd.OpenForm "ReportError" Forms!reporterror!RecordID = Me!RecID Forms!reporterror!PatientID = Me!PatId...
3
by: BakelNB | last post by:
I am new to the .Net environment, so please bear with me. I am passing a form object (e.g. formA) to an existing form (e.g. formB) by setting a property value defined in formB to hold the formA...
1
by: Kevin S Gallagher | last post by:
I found this code (pretty sure it was from a MVP) for converting a string variable to a form object which works fine within a form. Take the code and place it into a code module and it fails on the...
6
by: The Frog | last post by:
Hi Guys, Just wanting some opinions on best method to approach this. I am working on an Access97 db and we have two forms and an ADO connection object to contend with. The desired state is...
2
by: jesus4gaveme03 | last post by:
I ceated a automatic split form from a table called "Master NSN List." I then added 2 buttons "cmdShowHide" which toggles between showing and hiding the form section giving more room for the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.