Results 1 to 3 of 3
  1. #1
    pncbiz is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2020
    Location
    Maryland
    Posts
    66

    VBA Dlookup getting a syntax error

    I have the following VBA code in a Form_Current Procedure (on a subform nested within another subform on a main form)

    Private Sub Form_Current()
    strFilter = "ServiceID = " & Me!cboServiceID
    Me!cboBusinessNeedID = DLookup("BusinessNeedID", "Service", strFilter)
    End Sub
    When I open the main form, I get the following error:


    Run-time error '3075':

    Syntax error (missing operator) in query expression 'ServiceID = '.
    Here's the crazy part...when I click End in the dialog box, and it goes away and I navigate to the subform, the code did exactly what I needed it to do! Should I just set warnings to false and move on, or is there something to fix here?

    EDIT: Turning off warnings didn't help...

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    your error implies Me!cboServiceID is null

    suggest change your code to

    Code:
    if not isnull(Me!cboServiceID) then
        strFilter = "ServiceID = " & Me!cboServiceID
        Me!cboBusinessNeedID = DLookup("BusinessNeedID", "Service", strFilter)
    end if


    other possibility is you have a typo in Me!cboServiceID - better to use me. rather than me!. The me! late binds the control so any errors will not be seen until the code is executed whereas Me. will pick up errors when you compile your code.

  3. #3
    pncbiz is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2020
    Location
    Maryland
    Posts
    66
    Ajax,
    PERFECT!!! And thanks for the tip on Me. vs Me!
    Thanks,
    Phil

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

Similar Threads

  1. Syntax error with DLookUp()
    By shylock in forum Access
    Replies: 1
    Last Post: 04-05-2019, 01:42 PM
  2. DLookup syntax error
    By ljsincla in forum Programming
    Replies: 4
    Last Post: 09-09-2018, 08:55 PM
  3. Replies: 2
    Last Post: 01-04-2016, 09:40 AM
  4. Syntax Error in DLookUp
    By nick404 in forum Programming
    Replies: 7
    Last Post: 07-13-2015, 02:41 PM
  5. DLookup Syntax Error
    By uncletreetrunk in forum Programming
    Replies: 4
    Last Post: 07-30-2012, 02:29 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