 |
|
 |
ba1959nh Level: Scholar
 Registered: 10-05-2006 Posts: 39
|
How do I Pass Data to another Form?
I am working on a project using VB in MS Access 2003.
I have 2 forms:
SupportersForm & AddDonationForm
SupportersForm has a button which is used to launch AddDonationForm.
I need to pass the Supporter ID from SupportersForm to AddDonationForm so that AddDonationForm can write the Donation data to the db.
The examples that I have found on MSDN show how to do this if you instantiate a new form (like Form2) in the first form's button_click method. This is confusing to me since I want to launch an existing form (AddDonationForm).
I also tried to see if I could reference another form's control (txtSupporterID = SupportersForm.Supporters.ItemData(0)) but the second form does NOT recognize the first form and I get an Object Required error at run-time.
Is there a way to add a parameter to the OpenForm() or an equivalent Form load method?
or
... I guess I could usde a global, but that seems inefficient
or
What is the best way to do this?
I appreciate any help that can be provided.
Thanks,
Bill
|
|
19-05-2006 at 04:29 PM |
|
|
ba1959nh Level: Scholar
 Registered: 10-05-2006 Posts: 39
|
Re: How do I Pass Data to another Form?
Hi yronium......
I am getting an Object Required error ar runtime when AddDonationForm.Show is called.
Any ideas?
Thanks,
Bill
|
|
19-05-2006 at 08:24 PM |
|
|
yronium Level: Moderator

 Registered: 14-04-2002 Posts: 907
|
Re: How do I Pass Data to another Form?
quote: Am I missing something here?
You have missed just to specify that you're not working with VB but with VBA, and your IDE is not VB IDE but MSAccess IDE.
Anyway, nevermind the VBA language I only want you to understand the principle. My procedure to open a form by declaring it as an instance of an existing Form object rather than directly open it, does not matter that much.
quote: Private Sub btnLaunchAddDonationForm_Click()
On Error GoTo Err_btnLaunchAddDonationForm_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "AddDonationForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_btnLaunchAddDonationForm_Click:
Exit Sub
Err_btnLaunchAddDonationForm_Click:
MsgBox Err.Description
Resume Exit_btnLaunchAddDonationForm_Click
End Sub
So you open another existing form. The goal is to set a variable of it during opening.
In VB you have to set it before opening it, but I'm not sure you can still do it before in VBA. However, try modifying you code like followingPrivate Sub btnLaunchAddDonationForm_Click()
On Error GoTo Err_btnLaunchAddDonationForm_Click
AddDonationForm.SuppID = Me.txtCurrentID.Text
DoCmd.OpenForm AddDonationForm
Exit_btnLaunchAddDonationForm_Click:
Exit Sub
Err_btnLaunchAddDonationForm_Click:
MsgBox Err.Description
Resume Exit_btnLaunchAddDonationForm_Click
End Sub | It should work. If it doesn't, try switching the variable assigning instruction and the DoCmd.OpenForm line. But in this case you first open the form and then set its public variable. It means that, if you need that value to filter records, you got to requery the form after have passed the value.
I have no time now to try it in Access, as I got to go out, but you can do some tryouts by yourself. Just remember that VB is not the same of VBA, and Access forms are not the same of VB forms.
Let me know.
____________________________
Real Programmer can count up to 1024 on his fingers
|
|
20-05-2006 at 02:03 PM |
|
|
ba1959nh Level: Scholar
 Registered: 10-05-2006 Posts: 39
|
Re: How do I Pass Data to another Form?
I tried your code.
I have
Public SuppID As Long
at the top of the AddDonationForm code
(outside of any Sub or Function)
I pasted your code in my SupporterForm
With the calls you mentioned ordered this way...
AddDonationForm.SuppID = Me.txtCurrentID.Text
DoCmd.OpenForm AddDonationForm
I get the following error at runtime when I click the button:
Object Required
NOTE: the error dialog frame title is:
Microsoft Office Access
If I change the order of those 2 lines:
DoCmd.OpenForm AddDonationForm
AddDonationForm.SuppID = Me.txtCurrentID.Text
I get the following error:
Microsoft Office Access
The action or method requires a Form Name argument
I apologize about the VB versus VBA......
When I select View - Code from Access 2003
the pgm launched says Microsoft Visual Basic
(in the title bar) and when I click Help - About, it says:
Microsoft Visual Basic 6.3.
Could Access be launching the wrong VB application?
H E L P
Thanks again for your patience.....
Bill
|
|
20-05-2006 at 06:56 PM |
|
|
|
|
 |
 |