Results 1 to 9 of 9
  1. #1
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295

    Finding error in query vba code

    Good Day,



    I am trying to access a value in a table using VBA DLookup code. However I am unsuccessful.

    Can anyone please advise what is wrong with my code. I am sure the table exist and the field of reference exist also.

    Here is the code that I am using:

    The error message says it cannot find the input table or the query "RecBookNum"

    [ICODE]

    Private Sub Post_Deposit_Click()


    Dim Y As Integer
    Y = DLookup("ReceiptBook", "RecBookNum", "OrderID ='" & Me.[Order ID] & "'")

    MsgBox Y

    End Sub

    [/ICODE]

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    The single quote delimerters are not needed if OrderID is numeric. Try:
    Y = DLookup("ReceiptBook", "RecBookNum", "OrderID =" & Me.[Order ID])
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    this expects OrderID to be a string since you used quotes.
    ReceiptBook is the field to return
    RecBookNum is the table/query

    if OrderID is numeric, remove quotesL
    = DLookup("ReceiptBook", "RecBookNum", "OrderID =" & Me.[Order ID] )

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    The single quote delimerters are not needed if OrderID is numeric. Try:
    Y = DLookup("ReceiptBook", "RecBookNum", "OrderID =" & Me.[Order ID])

    Are you sure you have these (
    "ReceiptBook", "RecBookNum") in the right order. Is "ReceiptBook" the name of the field whose value you want?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Thanks Bob.
    Your suggestion is correct, however the problem persists. Please note that the error messages states that there is not such table.....

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Perhaps then, as I suggested earlier, you may need:
    Y = DLookup("RecBookNum","ReceiptBook", "OrderID =" & Me.[Order ID])
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Thank again: You are so correct. They are in the wrong order. It's working fine now.

    Have a great day all.

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by George View Post
    Thank again: You are so correct. They are in the wrong order. It's working fine now.

    Have a great day all.
    You're Welcome. Always glad to help if I can.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

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

Similar Threads

  1. Finding error in query vba code
    By George in forum Programming
    Replies: 4
    Last Post: 03-17-2021, 06:19 PM
  2. Writing code for finding Null value field
    By Raveen1609 in forum Access
    Replies: 5
    Last Post: 12-12-2020, 10:05 PM
  3. Replies: 1
    Last Post: 05-22-2018, 07:47 AM
  4. Replies: 9
    Last Post: 03-26-2015, 03:51 PM
  5. Syntax Error in my Query Code
    By PPat in forum Queries
    Replies: 5
    Last Post: 04-19-2013, 03:12 PM

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