1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Using Access Form to Enter Parameter Value

Discussion in 'Business Applications' started by willydigger, Jan 16, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. willydigger

    willydigger Thread Starter

    Joined:
    Jul 24, 2003
    Messages:
    112
    I want to build a form that has several buttons.
    Each button will hold a parameter value for a query.
    When the user clicks on the button it will open the query and automatically provide the parameter data so that the query only opens with the select data.

    For example, there are three buttons (1,2,3). When you click the "1" Button, it will open the query and enter "1" into the parameter so that the query opens with all data that fits the "1" criteria.

    Can someone give me an example of the proper code?
     
  2. cristobal03

    cristobal03

    Joined:
    Aug 5, 2005
    Messages:
    3,086
    It sounds like you're taking an odd approach. Have a gander at this FAQ from AccessVBA and see if that doesn't give you some ideas.

    chris.
     
  3. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,896
    Chris, this is not actualy an odd approach at all as it can be used for multiple searching and Wild card searching.
    willydigger, do not use the Form to pass parameters as such, use it as the basis of the criteria row of the query. Place a code like this in the Criteria row of your query -
    Like "*" & [Forms]![Form Name]![Field Name] & "*"
    where form Name is the name of your form and Field name is the name of your form which has a field on it containing what you want to search for, it can be a hidden field.
    This code will find any record that has the data in the form's field anywhere within the Tables field ie pattern match. If you want it to only match exact data use this instead -
    [Forms]![Form Name]![Field Name]
     
  4. cristobal03

    cristobal03

    Joined:
    Aug 5, 2005
    Messages:
    3,086
    That's what I meant by "odd." If you're going to use a custom form, use textbox controls rather than parameter popups.

    I meant the description of the proposed solution was unusual, not the requirement.

    chris.
     
  5. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,896
    Sorry Chris, I misunderstood.
     
  6. willydigger

    willydigger Thread Starter

    Joined:
    Jul 24, 2003
    Messages:
    112
    So what will the code look like in the button code? This is the standard code to open the query (a report of a query in this case):
    Code:
    Private Sub btnViewReport_Click()
        Dim stDocName As String
    
        stDocName = "Equipment Query"
        DoCmd.OpenReport stDocName, acPreview
    
    End Sub
     
  7. cristobal03

    cristobal03

    Joined:
    Aug 5, 2005
    Messages:
    3,086
    willydigger, did you read the FAQ I linked? It has code examples of what you need to do.

    For now, you can use the WhereCondition argument of the OpenReport method to specify a criterion or criteria at run-time. For instance, if you wanted to generate a report of all the customers in a given state, and if on your form you had a textbox control named txtState that accepted valid state abbreviations, you could do something like this:

    Code:
    Private Sub cmdGetReport_Click()
      DoCmd.OpenReport "rptCustomersByState", _
                       acPreview, _
                       , _ ' necessary so required 3rd argument is not omitted
                       "[StateField] = '" & Me.txtState & "'"
    End Sub
    
    That's an extremely limited example. There are more--and better--examples in the FAQ, including a demo search routine that you can modify for use in your database.

    chris.

    [edit]
    No worries whatsoever (y)
    [/edit]
     
  8. willydigger

    willydigger Thread Starter

    Joined:
    Jul 24, 2003
    Messages:
    112
    Thanks for the help guys. I created a listbox and had the query criteria reference the listbox like OBP suggested.
     
  9. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Solved Using Access
  1. fred615
    Replies:
    36
    Views:
    1,003
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/434635

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice