Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    37

    Unanswered: Passing parameter from combo box to query

    Hi I am trying to run a query by choosing a parameter from the drop-down of a combo box and to use the chosen parameter as a filter for the query (query1). My combo is called combotest and the parameter is called "name". I have enter [name] into the criteria field of the query.

    here is the code:

    Dim db As DAO.Database
    Dim qry As DAO.QueryDef

    Set db = Access.currentdb

    Set qry = db.QueryDefs("query1")
    qry.Parameters("[Name]").Value = Me.Combotest.Value
    DoCmd.OpenQuery qry, acNormal, acEdit

    whenever I run it I gt the following error message:
    "an expression you entered is the wrong data type".

    Help!

  2. #2
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580
    Put a breakpoint against this line of code>

    qry.Parameters("[Name]").Value = Me.Combotest.Value

    Then debug.print Me.Combotest.Value

    Is this returning what you would expect?

    What datatype is it?

    What datatype does the parameter require?
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  3. #3
    Join Date
    Mar 2009
    Posts
    37
    The field requires text. I now have:
    Set qry = db.QueryDefs("query1")
    'qry.Parameters("[Name]").Value = Me.Combotest.Value
    Debug.Print Me.Combotest.Value
    DoCmd.OpenQuery "query1", acNormal, acEdit

    what is the debug.print me... supposed to do? Now it prompts me to input a parameter against [name] and then runs the query.

  4. #4
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580
    Sorry - I wasnt being clear;

    Put a breakpoint on the line of code

    qry.Parameters("[Name]").Value = Me.Combotest.Value

    Run the code and when it stops type

    debug.print Me.Combotest.Value

    In the immediate window and press enter.

    What does this respond with?
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

Posting Permissions

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