Runtime Error 3265

gwill23

Registered User.
Local time
Today, 00:03
Joined
Jan 22, 2008
Messages
11
I get this error message when running this code and it fails on the DLookup line.

rs!Emp# = DLookup("[EmpID]", "Tbl_TK_Employee", "[EmpUserID] = '" & UserID & "'")

Here is the full code:

Private Sub ClockIn_Click()
Dim rs As New ADODB.Recordset
Dim UserID As String
UserID = fOSUserName()
rs.Open "tbl_TK_TimeWorked", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rs.AddNew
rs!Emp# = DLookup("[EmpID]", "Tbl_TK_Employee", "[EmpUserID] = '" & UserID & "'")
rs!Date = Now()
rs!StartTime = Now()
rs!Task = DLookup("[id]", "Tbl_TK_TaskList", "[task] = Clocked In")
rs.Update
rs.Close
Set rs = Nothing
End Sub

fosusername() pulls the windows userid I am logged in with. I simply want the user to click a button and it will log the empid from the employees table into the emp# field in the timeworked table.

THis is what the table looks like. So worries no sensitive info here :). As you can see the first record has the information I need.

Tbl_TK_EmployeeEmpIDEmpFNameEmpLNameEmpUserIDEmpAccessLvlABD100001GUNTHERWILLIAMSgwill23AdminABD100002STEVEBARELAsteveMangerABD100003GAILWILLIAMSgailSuperABD100004ANTHONYWILLIAMSwillEmployeeABD100006SUSANBRUST
NoneABD100008DEBORAHHUGHES
NoneABD100009PETERNORTHCUTT
NoneABD100011SETHROBERTS
NoneABD100012RANDALLLADMAN
NoneABD100016KIMBRANDON
NoneABD100017ALICEPENDERGRASS
None

Any ideas?
 
The DLookup looks okay to me (though the second one doesn't). I wonder if it's the inadvisable symbol in the field name. Try

rs![Emp#] = DLookup("[EmpID]", "Tbl_TK_Employee", "[EmpUserID] = '" & UserID & "'")
 
That did it thanks. Glad I found that early on. I'll get that changed in the table.
 
That is definitely the better solution. Glad we got it sorted out.
 

Users who are viewing this thread

Back
Top Bottom