Results 1 to 4 of 4
  1. #1
    p2565 is offline Novice
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    2

    Query using form

    Hi,
    I'm a beginner in using MS Access. I need to create a form for querying data from a table. The form has has a check box for each column in the table to select the columns that need to be displayed and there are a multiple text boxes in the form where the user can specify the search parameters. The results must be displayed at the click of a button in the form.

    I have not been able to find help with the VB code for running the query. I would be thankful if anyone could help me with an example of the code or direct me to help.

    Thanks

  2. #2
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    I'm not sure I understand what you're trying to achieve with the checkboxes for the columns but you might want to see if you can modify the Query By Form example provided by MS:
    http://support.microsoft.com/kb/286828

  3. #3
    p2565 is offline Novice
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    2
    Thank you for the help.
    Firstly, I was not able to find the 'Stored procedure' in the 'other' group of the 'create' tab in Access 2007.

    The example shown does not solve my problem of selecting columns for display.

    Assume, I have 5 columns (student_id, first_name, last_name, phone, email)
    In the query form, I have 5 check boxes for each of the columns.
    I want to implement the query such that if check box is selected, then include that column in the SELECT statement.

    Eg. if first_name and last_name are selected, SELECT first_name,last_name FROM stu_table WHERE student_id = [some parameter in form].

    I'd be thankful if you could help me with this.

  4. #4
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    If you're comfortable enough with SQL you can create an SQL string in code based on the selections made and use it as a query:

    Dim rst As New ADODB.Recordset
    Dim cnn As New ADODB.Connection
    Dim strSQL As String

    strSQL = [Create your SQL string]

    Set cnn = CurrentProject.Connection
    rst.Open strSQL, cnn, adOpenDynamic, adLockOptimistic
    ...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query to only show a value in a form from a query
    By cwwaicw311 in forum Queries
    Replies: 28
    Last Post: 03-27-2010, 02:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums