Run time error 2471

John thomas

Registered User.
Local time
Today, 15:24
Joined
Sep 4, 2012
Messages
206
When running the following code I get
RunTime Error 2471


The expression you entered as a query or parameter produced this error [phone no 1 ]
All the code works great except the last bit it should put a phone number into the field TelNumber

Private Sub Command60_Click()
DoCmd.OpenForm "InvCusDetailsForm"
DoCmd.GoToRecord , , acNewRec
Forms!InvCusDetailsForm!CusID = Forms!CustomeDetailsOnly!IDCustomer
DoCmd.Close
DoCmd.OpenForm "InvCusDetailsForm"
DoCmd.GoToRecord , , acLast
Forms!InvCusDetailsForm!Title = DLookup("Title", "[customer Details]", "IDCustomer =" & Forms![InvCusDetailsForm]!CusID)
Forms!InvCusDetailsForm!surname = DLookup("Surname", "[customer Details]", "IDCustomer =" & Forms![InvCusDetailsForm]!CusID)
Forms!InvCusDetailsForm![AddressLineOne] = DLookup("[Address line 1]", "[customer Details]", "IDCustomer =" & Forms![InvCusDetailsForm]!CusID)
Forms!InvCusDetailsForm![AddressLineTwo] = DLookup("[Address line 2]", "[customer Details]", "IDCustomer =" & Forms![InvCusDetailsForm]!CusID)
Forms!InvCusDetailsForm![Town] = DLookup("[Town]", "[customer Details]", "IDCustomer =" & Forms![InvCusDetailsForm]!CusID)
Forms!InvCusDetailsForm![Town] = DLookup("[Town]", "[customer Details]", "IDCustomer =" & Forms![InvCusDetailsForm]!CusID)
Forms!InvCusDetailsForm![PostCode] = DLookup("[Post code]", "[customer Details]", "IDCustomer =" & Forms![InvCusDetailsForm]!CusID)
Forms!InvCusDetailsForm![TelNumber] = DLookup("[Phone No 1]", "[customer Details]", "IDCustomer =" & Forms![InvCusDetailsForm]!CusID)
End Sub
 
Why not use Recordset object? Much efficient and better even. Regarding your error, are you sure that the Phone No 1 field in the table Customer details table is spelt correctly (or even exists)?
 
Re: SOLVED

Thanks for every ones help
The problem was an extra space in the table field (typo)
 
I would still advise that you look into (and use) one of the methods in the links provided. What you're currently doing is hitting the database 8 times (using DLookup) just to pull one record that matches a certain criteria. And on top of that you're cycling through all records using acLast to get to the last record. All of these things are unnecessary
 

Users who are viewing this thread

Back
Top Bottom