Results 1 to 7 of 7

Thread: Open Form

  1. #1
    Join Date
    May 2004
    Posts
    55

    Unanswered: Open Form

    I have two command buttons on a form that open the same form "DATA" but use two different queries. Is it possible to do this or is there an easier way?

    Thanks,

    DH

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    In the On Click event of each button:


    Code:
    Dim StrgWhere As String
     
    StrgWhere = "blah, blah, blah"
    DoCmd.OpenForm "DATA",,,StrgWhere


  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    You can just change the RecordSource of the form per VB better than using two Buttons..

  4. #4
    Join Date
    Sep 2003
    Location
    Birmingham, UK
    Posts
    121
    Combination of both replies.

    CyberLynx is suggesting that you pass 'Openargs' to the form that you're opening and hammbakka is suggesting that you change the recordsource of the form (DATA) depending on what 'OpenArgs' the form is opened with.

    So with OnClick Event of button1 enter :
    Docmd.OpenForm "Data",,,"Button1"

    Then in the Load Event of the Form (Data) type something like

    If Me.OpenArgs = "Button1" then
    Me.RecordSource = "Query1" (or the actual SQL from the query)
    Else
    Me.Recordsource = "Query2"
    End If

    Me.Requery


    Hope this helps

  5. #5
    Join Date
    May 2004
    Posts
    55
    Quote Originally Posted by SexualChocolate
    Combination of both replies.

    CyberLynx is suggesting that you pass 'Openargs' to the form that you're opening and hammbakka is suggesting that you change the recordsource of the form (DATA) depending on what 'OpenArgs' the form is opened with.

    So with OnClick Event of button1 enter :
    Docmd.OpenForm "Data",,,"Button1"

    Then in the Load Event of the Form (Data) type something like

    If Me.OpenArgs = "Button1" then
    Me.RecordSource = "Query1" (or the actual SQL from the query)
    Else
    Me.Recordsource = "Query2"
    End If

    Me.Requery


    Hope this helps

    Hey!! I tried this:


    Private Sub TOOL_ENGINE_Load() //Form Name
    If Me.OpenArgs = "GO" Then
    Me.RecordSource = "LOC_MAP1"

    Else
    Me.RecordSource = "TOOL_ENGINE" //Query Name
    End If

    Me.Requery

    End Sub

    One thing I forgot to mention was that the two buttons are on two separate forms but that shouldn't matter. The above code works when "GO" is not clicked. It opens TOOL_ENGINE form using query"TOOL_ENGINE". But when I click on GO it comes up with "Enter Parameter Value" which is used in the query TOOL_ENGINE. I am not sure why it does not use the query LOC_MAP1.

    Any suggestions??

    Thanks,
    D

  6. #6
    Join Date
    Nov 2003
    Posts
    1,487
    Actually...I meant it to be a WHERE clause.

    Did I put in to many commas



  7. #7
    Join Date
    Sep 2003
    Location
    Birmingham, UK
    Posts
    121

    Talking

    Enter parameter value error normally occurs when a query can't find one or more of the criteria that you've specified in it. Instead of changing the recordsource to 'point' to a different query (Me.RecordSource = 'query1') change the RecordSource to the actual sql statement (Me.RecordSource = "SELECT blah, blah, blah.

    Also what criteria have you specified and where do the parameters come from?

    Cyber : It didn't occur to me that you were trying the 'Where' clause!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •