Results 1 to 6 of 6
  1. #1
    allstar45 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    35

    Question VBA DLookup error: "you have canceled a previous operation"

    so, this is my code:


    Private Sub Command8_Click()
    Dim nameInput As String
    Dim noomber As Variant
    'Prevent Blank DB entrys.
    If Not (Forms!frmInputLO.txtName = "") Then

    Forms!frmInputLO.txtName.SetFocus
    nameInput = Forms!frmInputLO.txtName

    noomber = DLookup("name", "tblLOs", "name = nameInput") 'ERROR COMES ON THIS LINE

    If Not (noomber = Null) Then
    code...
    Else
    MsgBox "That Learning Objective already exists."


    End If


    Else
    MsgBox "Please give the Learning Objective a name."
    End If
    End Sub


    The goal of this is to check to see if a record already exists before adding a new one.
    I'm pretty sure I'm using DLookup wrong, but I can not figure out how..

    Thanks

  2. #2
    irish634 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    48
    Try this: DLookup("[name]", "tblLOs", "name=" & nameInput)

  3. #3
    allstar45 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    35
    that did not work either, I might add that using the expression:
    noomber = DLookup("name", "tblLOs", "name = 'thingie'")
    works, and returns Null (there is no 'thingie' in the names)

    noomber = DLookup("name", "tblLOs", "name = 'Ted'")
    works, and returns "Ted" (there is a 'Ted' in the names)

    BUT
    noomber = DLookup("name", "tblLOs", "name = " & nameInput)
    gives the "cancelled a previous operation" error

  4. #4
    irish634 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    48
    Quote Originally Posted by allstar45 View Post
    that did not work either, I might add that using the expression:
    noomber = DLookup("name", "tblLOs", "name = 'thingie'")
    works, and returns Null (there is no 'thingie' in the names)

    noomber = DLookup("name", "tblLOs", "name = 'Ted'")
    works, and returns "Ted" (there is a 'Ted' in the names)

    BUT
    noomber = DLookup("name", "tblLOs", "name = " & nameInput)
    gives the "cancelled a previous operation" error
    Try it without a space between name and =
    DLookup("[name]", "tblLOs", "name= " & nameInput)

    Also try: DLookup("[name]", "tblLOs","[name] = '" & nameInput & "'")

    (Watch brackets and spaces)

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Also, this statement

    If Not (noomber = Null) Then is incorrect

    There is nothing = Null. Null is unKnown

    You test with If(IsNull(noomber)) then...

  6. #6
    allstar45 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    35
    Thanks for the input

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

Similar Threads

  1. Replies: 2
    Last Post: 11-04-2011, 02:45 AM
  2. Replies: 1
    Last Post: 06-07-2011, 09:10 PM
  3. ComboBox "Select" and "DLookUp"
    By witooldas in forum Forms
    Replies: 0
    Last Post: 03-23-2011, 03:31 AM
  4. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM
  5. Replies: 2
    Last Post: 11-02-2009, 10:14 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