Results 1 to 7 of 7
  1. #1
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    216

    Why don't this query work?

    I hope someone will show me how to make this query work. I do have a table named tblCalendar with a field named pubLngProposalNo. There is a record in it containing proposal number 20250767 and a field named fTxtPrebill containing the value of yes. Below is my code.

    Public Function modCal_Mine()


    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim sqlQuery As String

    pubLngProposalNo = 20250767

    Set db = CurrentDb
    sqlQuery = "SELECT * FROM tblCalendar WHERE rs![fLngProposalNo] = " & pubLngProposalNo & " AND rs![fTxtPrebill] = 'yes'"
    Set rs = db.OpenRecordset(sqlQuery)

    Do While Not rs.EOF
    Debug.Print rs!fLngProposalNo
    rs.MoveNext
    Loop

    rs.Close
    Set rs = Nothing
    Set db = Nothing
    End Function

    Thank you in advance for your help

  2. #2
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    216
    I failed to mention that I get Run-Time error '3061': Too few parameters. Expected 1. Sorry about that.

  3. #3
    XeviBatlle is online now Novice
    Windows 11 Office 365
    Join Date
    Aug 2025
    Posts
    2
    The column names in the sql statement must reference to the names of the table, not the to the recordset, something like this:
    Code:
    sqlQuery = "SELECT * FROM tblCalendar WHERE [fLngProposalNo] = " & pubLngProposalNo & " AND [fTxtPrebill] = 'yes'"
    '"

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Is ftxtprebill a Boolean (yes/no) field or a text field?
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    No need for domain name in fieldnames, unless the fieldnames are duplicated between domains.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    I would also clarify if proposal number 20250767 is text or numeric- this sort of value is usually stored as text since I wouldn’t expect any maths to be done on it and at some point could contain non numeric characters. As a number it had a small benefit of taking less space than the text equivalent

  7. #7
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    216
    Thank you XeviBatlle , It works now. Things are so simple when you know what you are doing.
    islagogs, the

    ftxtprebill is a text field
    Welshgasman, thanjks for the additional info.
    CJ_London, now I am wordering if I created proposal numbers, property numbers, and humpteen others wrong by making them

    numeric instead of text. They are all numeric.
    Again thanks to all.

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

Similar Threads

  1. Replies: 6
    Last Post: 04-24-2022, 11:06 PM
  2. Replies: 3
    Last Post: 10-21-2018, 08:24 AM
  3. Replies: 6
    Last Post: 01-28-2014, 03:01 PM
  4. Replies: 4
    Last Post: 08-31-2012, 12:55 PM
  5. Getting an error and don't know why
    By brandonze in forum Programming
    Replies: 3
    Last Post: 08-02-2011, 07:34 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