Results 1 to 2 of 2
  1. #1
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100

    Syntax error with DLookUp()

    I have a table titled "IPAddress". One of the fields is "IP" defined as short text. This table contains IP Addresses that exist for our servers. Before adding a new IP Address to the table, I want to make sure that the IP I am adding doesn't already exist in the table. I am using DLookUp() to determine this. My code is:


    Code:
    Lvar = DLookup("[IP]", "IPAddress", "[IPAddress].[IP] = " & NewIP)
    Lvar is Dimmed as a variant, NewIP is dimmed as a string. I am getting the following error: "Run-time error '3075: Syntax error in number in query expression "'[IPAddress].[IP] = 140.106.55.351'. I should also mention that NewIP is being used in the Append Query and works fine. I have also tried the DLookUp with just "[IP] = " & NewIP) and get the same error.

    Can anyone help?

  2. #2
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    Never mind... I have already solved this one. My modified code:

    Code:
        If IsNull(DLookup("IP", "IPAddress", "[IPAddress].IP = '" & NewIP & "'")) Then
            ''' Insert the new IP Address
            DoCmd.RunSQL "INSERT INTO IPAddress (IP, IPType, FriendlyName, Ports) VALUES" & _
            "('" & NewIP & "', '" & NewIPType & "', '" & NewFNm & "', '" & NewPort & "')"
            
            ''' Close the frmNewIPAdr and return to frmIPAddresses
            DoCmd.Close acForm, "frmNewIPAdr", acSaveNo
        Else
            ''' The IP Address already exists display a message and exit the form
            myMsg = MsgBox("The IP Address already exists.  Enter a better IP!", vbInformation, "IP Already Exists")
            DoCmd.CancelEvent
            Me.txtNewIPAdr.SetFocus
            Exit Sub
        End If
    Works perfectly.

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

Similar Threads

  1. DLookup syntax error
    By ljsincla in forum Programming
    Replies: 4
    Last Post: 09-09-2018, 08:55 PM
  2. Replies: 3
    Last Post: 08-17-2018, 07:56 AM
  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