Results 1 to 15 of 15
  1. #1
    breezett93 is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    53

    Operator and Null errors with Dlookup

    On a form, I'm trying to compare two dates. Date A is located in Table A, and Date B is located in Table B. They are related by both tables having the column LinkedColumn. LinkedColumn is a PK in Table B, but not in Table A.



    The record source of the form is Table A; so I am trying to bring Date B onto the form using Dlookup. I'd like to avoid changing the record source because the form has a lot of other sections that rely on Table A.
    The strangest part is that sometimes it works and sometimes it doesn't.

    Here is the actual code of what I've been trying:

    Code:
    Dim dateB as variant     \\using As Date was also not working
    
    dateB = Dlookup("Date B", "Table B", "Table B.LinkedColumn = Table A.LinkedColumn"
    dateB = Dlookup("Date B", "Table B", "LinkedColumn = Table A.LinkedColumn"
    dateB = Dlookup("Date B", "Table B", "LinkedColumn = Table​ B.LinkedColumn"
    dateB = Dlookup("Date B", "Table B", "LinkedColumn = " & Dlookup("LinkedColumn", "Table A"))
    dateB = DLookup("Date B", "Table B", "TableB.LinkedColumn =" & Forms![Form]!LinkedColumn)
    There's probably several other combinations that I've tried that I am forgetting. Every error either says there is a operator error in the criteria part or an invalid use of null.

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,406
    Probably because of spaces in object names. Either redefine and remove all spaces or enclose names with spaces in brackets [], like [Date B].

  3. #3
    breezett93 is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    53
    Those aren't the actual names. Sorry for the confusion. All actual names are one word.

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The last of the 4 options you listed should work with the change shown in red, and with blanks in the field and table names removed:

    dateB = DLookup("DateB", "TableB", "TableB.LinkedColumn =" & Me!LinkedColumn)

    The only things that might cause that to fail are a) there is no control called LinkedColumn on the form or b) the form contains a blank record, i.e. LinkedColumn is Null.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Why not use real names?

    LinkedColumn fields are number type?

    Don't need VBA for this and if the form is Continuous or Datasheet, every record would show the same result. Put expression in textbox ControlSource: = DLookup("DateB", "TableB", "LinkedColumn =" & [LinkedColumn])

    Alternatively, include TableB in the form RecordSource (join type "Include all records from TableA...") and bind textbox to TableB DateB field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    breezett93 is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    53
    Quote Originally Posted by John_G View Post
    The last of the 4 options you listed should work with the change shown in red, and with blanks in the field and table names removed:

    dateB = DLookup("DateB", "TableB", "TableB.LinkedColumn =" & Me!LinkedColumn)

    The only things that might cause that to fail are a) there is no control called LinkedColumn on the form or b) the form contains a blank record, i.e. LinkedColumn is Null.
    Made that change and the exact error is:
    Run-time error 3075: Syntax error (missing operator) in query expression 'OrdTbl.OrdId ='.

    LinkedColumn/OrdId is definitely not Null. I entered test data myself. There is no control on the form for OrdId. There is a subform that displays part of a table with it though.

  7. #7
    breezett93 is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    53
    Quote Originally Posted by June7 View Post
    Why not use real names?

    LinkedColumn fields are number type?

    Don't need VBA for this and if the form is Continuous or Datasheet, every record would show the same result. Put expression in textbox ControlSource: = DLookup("DateB", "TableB", "LinkedColumn =" & [LinkedColumn])

    Alternatively, include TableB in the form RecordSource (join type "Include all records from TableA...") and bind textbox to TableB DateB field.
    If the actual names are more useful, I can provide that.

    LinkedColumn/OrdId is a number type in both tables.

    The form is Single Form.

    " Put expression in textbox ControlSource: = DLookup("DateB", "TableB", "LinkedColumn =" & [LinkedColumn])" gives me #Name? each time.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Then Access can't find a name used in the expression. Make sure spellings are correct.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Is tableB the actual name of the table, or is it OrdTbl? Is "LinkedColumn" the actual name of the field in TableB/OrdTbl, or is it OrdID? Is DateB the actual field name?

    Any one of those can cause the #Name error.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    OP already said in post 3 these are dummy names and offered in post 7 to provide real names. I expect breeze has now learned that using real names in post would be better.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    breezett93 is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    53
    OrdTbl, OrdId, and ShpDt are the actual names.

  12. #12
    breezett93 is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    53
    Quote Originally Posted by June7 View Post
    Then Access can't find a name used in the expression. Make sure spellings are correct.
    I have triple checked my spellings. Everything is okay there. I did mentioned earlier that sometimes it will work and sometimes it will not.

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Assuming you are using those correctly in the expression, it should work. At this point, I think we need to see your db. If you want to provide, follow instructions at bottom of my post.

    And what happens when it doesn't work - error message, wrong results, nothing?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Is there any chance that OrdTbl would not have a record where OrdID matches the value on the form? If the 'where' clause in the DLookup does not select a record, then the Dlookup return a Null, which may or may not generate an error, depending on how you use the Dlookup.

  15. #15
    breezett93 is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    53
    Quote Originally Posted by John_G View Post
    Is there any chance that OrdTbl would not have a record where OrdID matches the value on the form? If the 'where' clause in the DLookup does not select a record, then the Dlookup return a Null, which may or may not generate an error, depending on how you use the Dlookup.
    Good suggestion. I looked at IvcTbl (Table A) and noticed that some records do have a blank OrdId value. I then found that it looks like the OrdId is filled in later in the process than where I am currently trying to evaluate. But by then, it's too late as the record gets locked.

    So I need to do some backtracking. Will post more questions if I have any.

    Thank you.

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

Similar Threads

  1. Replies: 2
    Last Post: 07-28-2016, 11:11 AM
  2. Replies: 2
    Last Post: 01-04-2016, 09:40 AM
  3. Replies: 3
    Last Post: 11-15-2014, 07:43 PM
  4. Handling Null DLookup result
    By j6sander in forum Access
    Replies: 1
    Last Post: 07-19-2012, 11:07 AM
  5. Dlookup() for NULL
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 03-31-2011, 12:37 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