Results 1 to 6 of 6
  1. #1
    fbou is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2009
    Location
    Switzerland
    Posts
    3

    Error 3061 in VBA program

    Hello !
    I am french and a new member of your forum ...also beginner in Access programming...

    I want to print an invoice by selecting the invoice number in the input box...
    When I run the program it stops with the message : "error 3061, to few parameters , 1 expected" . The line which generates this message is the line :
    Set rst = db.OpenRecordset(sql)

    Here my code :
    Code:
    Option Compare Database
    Option Explicit
    Dim db As DAO.Database, rst As DAO.Recordset
    Sub PrintInvoice ()
    
    Set db = CurrentDb()     
    Dim rep As Integer
    Dim sql As String
    
    rep = InputBox("Please type the invoice number :", "Input invoice number")
    
    sql = "SELECT * FROM Invoices WHERE Invoices.[Invoicenumber]=" & rep & ";"
     
    Set rst = db.OpenRecordset(sql)
    Note : the type of Invoicenumber is Numeric



    I thank you in advance for your help !

    Have a nice day ,

    fbou

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    This usually implies that it cannot find a field based on what it is told. Is there acutally a field called Invoicenumber?

    You can also reduce the sql to

    Code:
    sql = "SELECT * FROM Invoices WHERE Invoicenumber=" & rep & ";"
    This is assuming that rep is number and not a string, if it is a string you need to code it as follows

    Code:
    sql = "SELECT * FROM Invoices WHERE Invoicenumber='" & rep & "';"
    Also I would introduce some validation, such as

    Code:
     
    If Rst.EOF = True And Rst.BOF = True Then
       MsgBox "Invoice number " & rep & " does not exist!"
       Set Rst = Nothing
       Set db = Nothing
       Exit Sub
    End If

    David

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Another rule of thumb with numerical fields is unless you will be doing math with the value, make the field a String.

  4. #4
    fbou is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2009
    Location
    Switzerland
    Posts
    3
    Dear all ,

    Please receive for your help my best regards !
    Many thanks !!

    Fbou (Switzerland-Genève)

  5. #5
    fbou is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2009
    Location
    Switzerland
    Posts
    3
    How to make this thread solved ?

    Fbou

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by fbou View Post
    How to make this thread solved ?

    Fbou
    Follow the link in my sig.

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

Similar Threads

  1. Ticketing program for community theater
    By Bill in forum Database Design
    Replies: 8
    Last Post: 11-22-2012, 02:15 PM
  2. Error 3061
    By Shanks in forum Queries
    Replies: 4
    Last Post: 09-16-2009, 07:13 AM
  3. Access chat program
    By cuneyt in forum Programming
    Replies: 1
    Last Post: 09-08-2009, 02:44 PM
  4. Do i need a custom program for this?
    By hokie in forum Programming
    Replies: 9
    Last Post: 07-17-2009, 06:27 AM
  5. Set focus to another program
    By DrewB in forum Programming
    Replies: 1
    Last Post: 06-24-2009, 06:38 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