|
-
Aug 17th, 2005, 08:34 AM
#1
Thread Starter
Addicted Member
Passing Parameters Into A Form [RESOLVED]
Hi guys,
I've been looking for a way to pass parameters into a form and then use that parameter in the subform once it's been passed. The situation is this - I have a few tables in the current database who's contents I'd like to display. I also have a main form with a command button. The idea is, once the button is clicked, a subform is opened that populates its text and list boxes with information from a particular table, depending on what value was passed in as a parameter (ie: DoComd.OpenForm <subformname>, OpenArgs:="First_Table" will open First_Table, DoCmd.OpenForm <subformname>, OpenArgs:="Second_Table" will open Second_Table etc. etc....)
My question is pretty general - how is this done?
The DoComd... OpenArgs example is something I found earlier but I've no idea how to get the subform to act based on the parameter that was passed into it.
Hope you can help,
Thanks
Last edited by MethadoneBoy; Aug 30th, 2005 at 08:17 AM.
Reason: Resolved
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Aug 18th, 2005, 03:20 AM
#2
Re: Passing Parameters Into A Form
On load of the form you would need to check the me.OpenArgs.
Add this to an sql statement for the form and set the recordseource (I think) property to the new sql statement. Then it may require a me.refresh/me.requery to get the requested data.
Worth a try to see if it works. Post up if it does/doesn't work.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Aug 23rd, 2005, 08:58 AM
#3
Thread Starter
Addicted Member
Re: Passing Parameters Into A Form
Thanks. Here's the latest -
I've passed a string parameter into the form, which I'm calling frmEdit. I have a button in frmEdit called CmdEnter. As this button's event procedure, I've instructed it to check Me.OpenArgs and display whatever the arguments are in a textbox, like so -
Dim str As String
str = "Display " & Me.OpenArgs
txtDisp.Text = Me.OpenArgs
It's not displaying the arguments at the moment. Am I on the right track here?
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Aug 23rd, 2005, 11:26 AM
#4
Frenzied Member
Re: Passing Parameters Into A Form
Show your exact DoCmd.OpenForm command
Try a messagebox in the open event of the new form ...
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Aug 23rd, 2005, 11:50 AM
#5
Frenzied Member
Re: Passing Parameters Into A Form
Hey! Your question was the solution to my problem! I was trying to set a Label in a Report, and it works if I pass an "OpenArgs" to the Report and use it to set the Label.Caption in the Report Open Event, but it does not work (on the 1st page) if I try to set the Label.Caption in the control Button click event!
Thanks, good luck, and good programming!
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Aug 23rd, 2005, 12:07 PM
#6
Frenzied Member
Re: Passing Parameters Into A Form
Here is my code that works ...
Code:
'>>> In Control Form Module
Private Sub Command0_Click()
Dim aWhere As String
Dim aStrArg As String
'Select a WHERE statement (from Global List) based on the Radio Box Group
aWhere = aDept(Me.Dpt_Chain.Value)
'Pass a String Argument to the Report to install in the Lable
aStrArg = "TEST 22"
'Open the Report and pass it a string ...
DoCmd.OpenReport "Price_1", acViewPreview, , aWhere, acWindowNormal, aStrArg
End Sub
'>>> In Report Code
Private Sub Report_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Me.Controls("Dpt_Label").Caption = Me.OpenArgs
End If
End Sub
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Aug 24th, 2005, 04:37 AM
#7
Thread Starter
Addicted Member
Re: Passing Parameters Into A Form
I've made some of the changes suggested here and I've studies the info available on the MSDN library. My code now reads like so -
VB Code:
'This is the code in the form that will open the second (or sub) form
Private Sub OpenEditForm()
Dim strRep As String
strRep = "Test Argument Passing"
Dim db As Database
Dim rs As Recordset
Dim sqlStr As String
Set db = CurrentDb()
DoCmd.SetWarnings (False)
DoCmd.OpenForm "frmEditMon", , , , , , strRep
End Sub
'This is the code in the subform
'CmdMonEnt is a command button
Private Sub CmdMonEnt_Click()
Dim str As String
str = "Display : " & Me.OpenArgs
'txtDisp is a textbox
txtDisp.Text = Me.OpenArgs
If Not IsNull(Me.OpenArgs) Then
MsgBox Me.OpenArgs
End If
End Sub
Everything compiles ok and there are no errors but the subform isn't displaying the argument string that I'm passing in to it. Any ideas?
Last edited by MethadoneBoy; Aug 24th, 2005 at 05:03 AM.
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Aug 24th, 2005, 10:18 AM
#8
Frenzied Member
Re: Passing Parameters Into A Form
DoCmd.OpenForm "frmEditMon", , , , , , strRep
IGNORE THIS ... I Confused OpenForm with OpenReport
I think you have 1 too many commas ... as I recall OpenArgs is the SIXTH parameter.
Last edited by Webtest; Aug 24th, 2005 at 10:29 AM.
Reason: Error ... short between the ears
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Aug 24th, 2005, 10:27 AM
#9
Frenzied Member
Re: Passing Parameters Into A Form
OOPS! OpenForm seems to have 1 more parameter than OpeReport ...
expression.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)
expression.OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)
Put a message box in the OPEN Event for the subform ... I'll bet you'll find it there. Pass the parameter to a Public (Global) variable in the Open Event code and it will be available to the rest of the code for the form.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Aug 30th, 2005, 08:16 AM
#10
Thread Starter
Addicted Member
Re: Passing Parameters Into A Form
Thanks - that pretty much clinched it.
This is the line of code that opens the form
DoCmd.OpenForm "<form name>", , , , , , strArgument
And this is the code in the Subform that gets the parameter
Private Sub Form_Load()
strArg = Me.OpenArgs
MsgBox "Parameter : " & strArg
End Sub
Thanks for all the help.
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|