Results 1 to 3 of 3

Thread: Parameter query

  1. #1
    Join Date
    Feb 2003
    Posts
    65

    Question Unanswered: Parameter query

    I have a form showing some customer data. The form is based on a query. On the form there is a combo box and the user can select different courses. My goal is to select a course from the combo and when press a command button, to filter the results on the form.

    Here is my code attached to the OnClick event of the command button:
    ------
    Private Sub ProcessButton_Click()

    Dim db As Database
    Dim qr As QueryDef

    Set db = CurrentDb
    Set qr = db.QueryDefs("WhoTook")

    Me.Form.RecordSource = "SELECT * FROM WhoTook WHERE CourseName = " & [Forms]![Tools].[SelectCourse]

    Me.Requery
    Me.Repaint

    End Sub
    ----

    When running the above code I am getting syntax error (missing operator in query expression CourseName = ...

    I just can't figure out what's wrong. You guys are much sharper then me...

    Thanks for the help.

    Jazz

  2. #2
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    Try putting qoutes around the course name

    Me.Form.RecordSource = "SELECT * FROM WhoTook
    WHERE CourseName = ' " & [Forms]![Tools].[SelectCourse] & " ' "

    Steve

  3. #3
    Join Date
    Feb 2003
    Posts
    65

    Question Missing controls on the form

    Thank you Steve,

    The syntax error disapeared, however this seems to be only one of many problems. When running the code with any selection of the combo, the form becomes blank - meaning no controls are visible (probably because the query does not return any results, so the record source is empty, but it shoud not - there are plenty of records available for the specific WERE condition).

    It must be a simple task - to filter the record source by one or many parameters. What am I doing wrong?

    Jazz

Posting Permissions

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