Results 1 to 10 of 10

Thread: Passing Parameters Into A Form [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    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...."

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    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.

    BOFH Now, BOFH Past, Information on duplicates

    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...

  3. #3

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    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...."

  4. #4
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Passing Parameters Into A Form

    Show your exact DoCmd.OpenForm command

    Try a messagebox in the open event of the new form ...
    Code:
    MsgBox Me.OpenArgs
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  5. #5
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    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

  6. #6
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    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

  7. #7

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    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:
    1. 'This is the code in the form that will open the second (or sub) form
    2.  
    3. Private Sub OpenEditForm()
    4.    
    5.     Dim strRep As String
    6.     strRep = "Test Argument Passing"
    7.     Dim db As Database
    8.     Dim rs As Recordset
    9.     Dim sqlStr As String
    10.     Set db = CurrentDb()
    11.     DoCmd.SetWarnings (False)
    12.     DoCmd.OpenForm "frmEditMon", , , , , , strRep
    13.    
    14. End Sub
    15.  
    16. 'This is the code in the subform
    17.  
    18. 'CmdMonEnt is a command button
    19. Private Sub CmdMonEnt_Click()
    20.     Dim str As String
    21.     str = "Display : " & Me.OpenArgs
    22.     'txtDisp is a textbox
    23.     txtDisp.Text = Me.OpenArgs
    24.     If Not IsNull(Me.OpenArgs) Then
    25.         MsgBox Me.OpenArgs
    26.     End If
    27. 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...."

  8. #8
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    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

  9. #9
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    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

  10. #10

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    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
  •  



Click Here to Expand Forum to Full Width