Results 1 to 2 of 2

Thread: Sql Help!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    9

    Sql Help!

    What's wrong with this code!
    I created the query in Access97 query design view and it works fine when the [qry test1] form is open.

    I then copied the SQL Statement to the current event of my form

    Every time it runs the code, I get an error saying:
    Run-time error 3061
    Too few parameters. Expected 1.


    dim db as database
    dim rs as recordset

    set db = currentdb
    Set rs = db.OpenRecordset("SELECT TBLMULTIORDERS.OrderID, TBLMULTIORDERS.Quantity, TBLMULTIORDERS.[NET TONS], [tblmultiorders].[net tons]*9.072 AS [Metric Tons] FROM TBLMULTIORDERS WHERE (((TBLMULTIORDERS.OrderID)=[Forms]![qry test1]![orderid]))")

    I also tried
    set rs = db.openrecordset("name of access querie") but I still recieved errors

    I am trying to run a query of tblmultiorders based on the orderid from my form.

    THANKS

  2. #2
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    The recordset is having difficulties in using a reference to a Form as it's criteria. Best to put the contents of your form field into a variable
    (i guess the form field is called orderid - would be clearer if you named it in standard naming convention - txtOrderID)

    Code:
    Dim db As Database
    Dim rs As Recordset
    Dim sCriterion As String
    
    sCriterion = Me.orderid
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT OrderID, Quantity, [NET TONS], [net tons]*9.072 AS [Metric Tons] " & _
    "FROM TBLMULTIORDERS " & _
    "WHERE datatype='" & sCriterion & "'")

Posting Permissions

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



Click Here to Expand Forum to Full Width