VBA DLookup gives Runtime Error '3464' (1 Viewer)

dmckie250

Registered User.
Local time
Today, 05:55
Joined
Sep 1, 2010
Messages
12
Hi everyone,

I have been struggling with this control all day - I have a form with a combo box [Employee ID] that looks up the value [Employee ID] from a table called tbl_Personnel_Details

This table is linked to another table called tbl_Personnel_Status_Update which contains the field [CBD_Code]. I use the query qry_Personnel_Current_Status to determine the most recent value for [CBD_Code] in relation to the [Employee ID].

I have been trying to use the following VBA code to update the combo box [Charge_Code] with the relevant [CBD_Code] using the AfterUpdate event on [Employee ID]:

Code:
Private Sub Employee_ID_AfterUpdate()
Dim EID, CBD As String

    EID = Me.Employee_ID.Value

'update charge code with employee's current CBD Code
    CBD = DLookup("[CBD_Code]", "qry_Personnel_Current_Status", "[Employee ID] = " & EID)
    
    Me.Charge_Code.Value = CBD
End Sub
Whenever I try to run it I get a message saying either "Runtime Error '2001' - you cancelled the previous event" or "Runtime Error '3464' - data type mismatch".

I have tried changing the query that it is getting the value for [Employee ID] from and it works fine (although it gives me a different value so this is not suitable). I have also used the correct query with different criteria (I used a field called [Equipment #]) and it works fine. the Employee ID field is a text field.

Does anyone have any suggestions why its not working? Or a better way to update the field [Charge_Code] with the CBD_Code that is associated with the selected Employee ID?

Thanks,

Duncan
 

missinglinq

AWF VIP
Local time
Today, 05:55
Joined
Jun 20, 2003
Messages
6,423
If Employee ID is Text the syntax would be

"[Employee ID] = '" & EID & "'"


Linq ;0)>
 

dmckie250

Registered User.
Local time
Today, 05:55
Joined
Sep 1, 2010
Messages
12
Ahhhhhhhhhhhhhhhh....

That's taken me about 3 hours trying all different possible ways of the using the Employee ID field in that statement. I will keep that solidly in mind for the future!

THANKYOU!!!!
 

Users who are viewing this thread

Top Bottom