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
spdouganAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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 WarrenApplications DeveloperCommented:
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 WarrenApplications DeveloperCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
spdouganAuthor Commented:
thanks for the help!  stupid errors will catch me every time!
0
Alan WarrenApplications DeveloperCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.