Results 1 to 4 of 4
  1. #1
    willkr is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2023
    Posts
    110

    Open Recordset with selection on two fields

    I have an open recordset command that works fine. It is

    Set recChkEntry = db.OpenRecordset("Select * From tblChecks Where [Check Number] = " & lngCheckNo)

    It works fine unless there are checks with the same check number in two separate accounts. I tried the following:

    Set recChkEntry = db.OpenRecordset("Select * From tblChecks Where [Check Number] = " & lngCheckNo & " And [Chk Account] = " & strChkAccount)



    This produces a syntax error.

    What am I doing wrong?

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    And that error and its message is??
    I'm guessing the account number is a string so it should be [Chk Account] = ' " & strChkAccount & " ' "
    I inserted spaces so you can distinguish the quotes, but you wouldn't use them, so

    [Chk Account] = '" & strChkAccount & "'"

    String and date references need to be delimited (quotes and octothorpes respectively)
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    willkr is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2023
    Posts
    110
    Thanks, Micron. That did the trick! I gave you a star.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Glad I could help!
    Thanks.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Open Recordset
    By lamore48 in forum Access
    Replies: 15
    Last Post: 02-15-2018, 07:25 PM
  2. Replies: 2
    Last Post: 04-17-2017, 11:26 PM
  3. Replies: 7
    Last Post: 04-15-2015, 02:47 PM
  4. Open recordset
    By Praveenevg in forum Access
    Replies: 2
    Last Post: 08-18-2014, 12:21 PM
  5. ADO Recordset.Open (SQL) does nothing
    By workindan in forum Programming
    Replies: 3
    Last Post: 06-23-2010, 02:07 PM

Tags for this Thread

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