Results 1 to 4 of 4
  1. #1
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81

    Question Syntax error (missing operator) in query expression when using DLOOKUP function

    I have a form that is used to manage incoming requests submitted. There's a process which imports them into the database. The form is bound to a query which essentially just includes requests in which "Open" is equal to true.
    So at any given time, there could be 10 items in the form, or there could be none whatsoever.


    In the Form_Current event, I have some code that pulls in the Request Type (e.g.: users submitting the form can pick a few diff options) through DLOOKUP.. This is then used in the subsequent "Select Case" portion to Show or Hide certain controls on the form.
    The problem I'm running into is when there's NO open requests - e.g.: the underlying data source of the form returning no results -- the form is error'ing out with the "Syntax error (missing operator) in query expression" error.
    When I click debug, it's on the "strAppType" variable.. So it's obviously not liking the fact that it's returning a null value..
    But I can't seem to figure out how to get past this. I tried using the NZ function around the DLOOKUP syntax but the same error returned when trying to open up the form.
    Any help would be appreciated. Thanks!

    Code:
    Dim strAppType As Variant
    Dim strEndDate As Variant
    Dim UserRoleCtrl As Control
    Dim UserToMirrorRoleCtrl As Control
    Dim frmHRS0014s As Form
    
    
    Set frmHRS0014s = Forms!frmSystem_Change_Requests_New
    
    
    strAppType = DLookup("[System_Affected]", "[qry_System_Changes_Open]", _
                       "[Request_Number] = " & frmHRS0014s!txt0014ID)
                         
    
    
    strRequestTypeENS = DLookup("[ENS_Request_Type]", "[qry_System_Changes_Open]", _
                         "[Request_Number] = " & frmHRS0014s!txt0014ID)
    
    
    
    
    On Error GoTo Err_Handler
    
    
    
    
    ShowControls True, "Default Info"
    ShowControls False, "User Info", "ENS", "HRIS PB", "HRIS.NET", "WexHealth"
    ShowControls False, "NewRole", "NewRoleENS", "NewRolePB", "NewRoleWex", "NewRoleNet"
    ShowControls False, "Screen Info", "Screen Info Net", "Screen Info ENS", "Screen Info PB"
     
    Select Case strAppType
        Case "ENS"
           ShowControls True, "ENS"
           Select Case strRequestTypeENS
                Case "Modify_Existing_User_Add", "Modify_Existing_User_Remove"
                ShowControls True, "User Info"
                Case "Create_New_Group"
                ShowControls True, "NewRole"
                ShowControls True, "NewRoleEns"
                Case Else
                ShowControls True, "Screen Info"
            End Select

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can try

    strAppType = Nz(DLookup("[System_Affected]", "[qry_System_Changes_Open]", "[Request_Number] = " & Nz(frmHRS0014s!txt0014ID, 0)), "")

    But you may need this:

    http://www.theaccessweb.com/forms/frm0022.htm

    for the form reference.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81
    Thank you! This worked perfectly!
    strAppType = Nz(DLookup("[System_Affected]", "[qry_System_Changes_Open]", "[Request_Number] = " & Nz(frmHRS0014s!txt0014ID, 0)), "")

    Quote Originally Posted by pbaldy View Post
    You can try

    strAppType = Nz(DLookup("[System_Affected]", "[qry_System_Changes_Open]", "[Request_Number] = " & Nz(frmHRS0014s!txt0014ID, 0)), "")

    But you may need this:

    http://www.theaccessweb.com/forms/frm0022.htm

    for the form reference.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 11-07-2017, 06:26 PM
  2. Replies: 5
    Last Post: 10-25-2017, 01:47 PM
  3. Replies: 4
    Last Post: 03-16-2016, 12:24 PM
  4. Replies: 2
    Last Post: 02-17-2014, 10:27 AM
  5. Replies: 9
    Last Post: 01-22-2013, 04:23 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