Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2003
    Posts
    17

    Unanswered: Run Query from code

    Hi,

    I have a small problem which I can't understand.

    I'm using a Query(open from code:
    Set Myquery = MyDB.OpenRecordset("Temp", DB_OPEN_DYNASET)

    The problem is that if I add a criteria to any field in the query the code gives me the error "Too few parameters. Expected 1" at the line SET Myquery......

    Where is the problem ???

    Thanks in advance
    Korado

  2. #2
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: Run Query from code

    Originally posted by Korado
    Hi,

    I have a small problem which I can't understand.

    I'm using a Query(open from code:
    Set Myquery = MyDB.OpenRecordset("Temp", DB_OPEN_DYNASET)

    The problem is that if I add a criteria to any field in the query the code gives me the error "Too few parameters. Expected 1" at the line SET Myquery......

    Where is the problem ???

    Thanks in advance
    Korado

    Try this.

    Dim MyDB as Database, Myquery as recordset
    Set MyDB = CurrentDb
    Set Myquery = MyDB.OpenRecordset("Temp", dbOpenDynaset)

    Gregg

  3. #3
    Join Date
    Jun 2003
    Posts
    17
    I have already this situation.

    The problem is somewhere else. It seems that "DAO.recordset" doesn't allow to put any criteria.

    Thanks anyway.

    Korado

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    you can certainly have criteria, but where are the values for the criteria supposed to come from?

    one way: use textboxes (or combos etc) on a form to feed criteria to your query. open the query in design view, click in the criteria box in the grid, and click the "magic wand" builder in the main menu.

    when the builder window opens -
    in the left pane:navigate through forms/all forms/textboxForm
    in the middle pane: double-click the textbox name.

    depending on what you are trying to achieve, you might have to use a hidden textbox. e.g. your criteria reads:
    Like Forms!Myform!myHiddenBox
    and you set "*test*" as the value in myHiddenBox when the user-visible textbox is edited.

    izy

  5. #5
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Question

    Originally posted by Korado
    I have already this situation.

    The problem is somewhere else. It seems that "DAO.recordset" doesn't allow to put any criteria.

    Thanks anyway.

    Korado

    Are you trying to open a query or are you trying to open a recordset based on a query?

    Gregg

  6. #6
    Join Date
    Jun 2003
    Posts
    17

    Run query from code

    I this means open a recordset then I'm opening a recorsdset based on the query:
    Dim MyDB as Database,
    Dim Myquery as recordset

    Set MyDB = CurrentDb()
    Set Myquery = MyDB.OpenRecordset("Temp", DB_OPEN_RECORDSET)

    Thanks
    Korado

  7. #7
    Join Date
    Jun 2003
    Posts
    17

    Run Query from code

    I have already done that, but still have the same problem.
    When I have a criteria, when the code run at line
    Set Choose = MyDB.OpenRecordset("qryChoose", dbOpenDynaset)
    It gives me the error:
    "Too few parameters. Expected 1"

    Thanks
    Korado

  8. #8
    Join Date
    Oct 2003
    Location
    Auckland
    Posts
    4
    have already done that, but still have the same problem.
    When I have a criteria, when the code run at line
    Set Choose = MyDB.OpenRecordset("qryChoose", dbOpenDynaset)
    It gives me the error:
    "Too few parameters. Expected 1"

    If you underlying query is prompting user for input you will get thois error.. maybe your criteria has an expression inclosed with [] (square brackets), or check that a parameter that is not beign used exists, by right clikcing and selecting parameters. If one does exist and you wnat to pass the parameter for vb, open the query and set the parameter before you open the recordset. ie.

    Set qdfChoose = .QueryDefs("qryChoose") '

    With qdfChoose
    .Parameters![one] = myvalue
    Set rstChoose = .OpenRecordset
    End With

    It may help if you post your sql.

  9. #9
    Join Date
    Jun 2003
    Posts
    17

    Run Query from code

    My parameter is actually combo box.
    The criteria expresion in a query is the following:
    [Forms]![MyForm]![Combo68]
    If I typ in a query criteria expresion a record value like "text", the I won't have the error.

    Thanks
    Korado

  10. #10
    Join Date
    Jun 2003
    Posts
    17

    Run Query from code

    Here is also the Query SQL :

    SELECT DISTINCT tblChoose.IDChart, tblChoose.ChartName
    FROM tblChoose
    WHERE (((tblChoose.[ChartName])=[Forms]![Myform].[Combo68]))
    ORDER BY tblChoose.ChartName;


    Thanks
    Korado

  11. #11
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    looks like [ChartName] is text: try the following

    dim strSQL as string
    strSQL = "SELECT DISTINCT tblChoose.IDChart, tblChoose.ChartName "
    strSQL = strSQL & "FROM tblChoose "
    strSQL = strSQL & "WHERE (((tblChoose.[ChartName])='" &[Forms]![Myform].[Combo68] & "')) "
    strSQL = strSQL & "ORDER BY tblChoose.ChartName;"
    Set Choose = MyDB.OpenRecordset(strSQL)

    izy

Posting Permissions

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