[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1836
  • Last Modified:

DLookup() and Runtime Error '2001'

i have a form with fields that i want populated by a combobox value
FirstName
LastName
Location
CampusPhone
OtherPhone

this is the code that throws the error, insisting that i cancelled the previous operation, and i can't figure out why or what operation i previously cancelled...

Private Sub UserID_AfterUpdate()
    Me.FirstName = DLookup("FirstName", "Contacts", "UserID= " & Me.UserID.Value)
    Me.LastName = DLookup("LastName", "Contacts", "UserID= " & Me.UserID.Value)
    Me.CampusPhone = DLookup("CampusPhone", "Contacts", "UserID= " & Me.UserID.Value)
    Me.OtherPhone = DLookup("OtherPhone", "Contacts", "UserID= " & Me.UserID.Value)
    Me.Location = DLookup("CampusLocation", "Contacts", "UserID= " & Me.UserID.Value)
    Me.Location = DLookup("Name", "ContactLocations", "ID = " & Me.Location.Value)
End Sub
0
spdougan
Asked:
spdougan
  • 4
  • 3
  • 3
  • +1
2 Solutions
 
flavoCommented:
what does this line do?? It looks aout of place...

Me.Location = DLookup("Name", "ContactLocations", "ID = " & Me.Location.Value)
0
 
spdouganAuthor Commented:
i keep a table for contacts (userid,firstname,lastname,campusphone,otherphone,campuslocation)
where contacts.campuslocation = integer, which refers to the id column in table contactlocations(ID,name).
0
 
flavoCommented:
ok.. try this


    Me.Location = DLookup("[Name]", "ContactLocations", "ID = " & clng(DLookup("CampusLocation", "Contacts", "UserID= " & Me.UserID.Value)))
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
flavoCommented:
instead of these 2 lines

 Me.Location = DLookup("CampusLocation", "Contacts", "UserID= " & Me.UserID.Value)
    Me.Location = DLookup("Name", "ContactLocations", "ID = " & Me.Location.Value)

Dave
0
 
Alan WarrenCommented:
Hi spdougan

try handling the error, but still leave scope to handle any other errors

Private Sub UserID_AfterUpdate()

On Error GoTo ReportError

    Me.FirstName = DLookup("FirstName", "Contacts", "UserID= " & Me.UserID.Value)
    Me.LastName = DLookup("LastName", "Contacts", "UserID= " & Me.UserID.Value)
    Me.CampusPhone = DLookup("CampusPhone", "Contacts", "UserID= " & Me.UserID.Value)
    Me.OtherPhone = DLookup("OtherPhone", "Contacts", "UserID= " & Me.UserID.Value)
    Me.Location = DLookup("CampusLocation", "Contacts", "UserID= " & Me.UserID.Value)
    Me.Location = DLookup("Name", "ContactLocations", "ID = " & Me.Location.Value)
   
ExitProcedure:
  On Error Resume Next
 
  DoCmd.Hourglass False
  DoCmd.SetWarnings True
 
  Exit Sub

ReportError:
  Dim strMsgText As String
  Select Case Err.Number
    Case 2001
      Resume ExitProcedure
    Case Else
      strMsgText = "Error in " & Me.Name & ".UserID_AfterUpdate()" _
        & vbCr & "Error number " & CStr(Err.Number) _
        & " was generated by " & Err.Source _
        & vbCr & Err.Description
      MsgBox strMsgText, vbExclamation + vbMsgBoxHelpButton, "Error", Err.HelpFile, Err.HelpContext
  End Select
  Resume ExitProcedure
   
End Sub


Alan


0
 
spdouganAuthor Commented:
so all interested can understand what's not apparently working for me, i posted my project at http://cs.georgefox.edu/~sdougan/sp.zip

the form with issues is the 'Create Request' form
0
 
Alan WarrenCommented:
Hi spdougan


FoxmailID is text so encapsulate in apostrophe's

    Me.FirstName = DLookup("FirstName", "Contacts", "FoxmailID = '" & Me.FoxmailID.Value & "'")
    Me.LastName = DLookup("LastName", "Contacts", "FoxmailID = '" & Me.FoxmailID.Value & "'")
    Me.CampusPhone = DLookup("CampusPhone", "Contacts", "FoxmailID = '" & Me.FoxmailID.Value & "'")
    Me.OtherPhone = DLookup("OtherPhone", "Contacts", "FoxmailID = '" & Me.FoxmailID.Value & "'")
    Me.Location = DLookup("Name", "ContactLocations", "ID = " & CLng(DLookup("CampusLocation", "Contacts", "FoxmailID = '" & Me.FoxmailID.Value & "'")))


Alan
0
 
spdouganAuthor Commented:
thanks for the help!  stupid errors will catch me every time!
0
 
Alan WarrenCommented:
hi spdougan

yeah I know what you mean.

I dont often use text primary keys, but if ever I do I prefix the field name  with 's'  sFoxMailID to jog my memory when working in code window.



Alan
0
 
flavoCommented:
I do the same Alan :-)

sTextField
lLongField
iIntegertField
dtDateField

Saves going back and forth into the table designer all the time, and reminds me to use the right " ' #

Good luck with your project spdougan!

Dave...
0
 
cmccurdyCommented:
Here it is, almost a year later and this answer is still valuable.  I also had the same stupid error.  Thanks!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now