DLookup Question

ARW17

Board Regular
Joined
Oct 31, 2016
Messages
109
I'm using DLookup for the first time and trying to wrap my brain around how it works and the syntax involved.

I want to basically append a table using a form.

Dim chgreqrec As Recordset
Set chgreqrec = CurrentDb.OpenRecordset("AttendanceEvents")
chgreqrec.AddNew


chgreqrec![Event Date] = txtPersonalDate
chgreqrec![Employee] = Employee
chgreqrec![EventTypeCode] = "P"

The code above runs fine. On the code below, I'm getting a type mismatch error. I have an option box where 1 signifies a full personal day and 2 & 3 are half days (am or pm). I want the start time to be the employee's scheduled start time for that particular day, which is held in tblSchedules. I want to report start time where the employee column in the table matches the employee listed on the form and then I want the start time for the correct day for that employee.


If opFullHalf = 1 Or opFullHalf = 2 Then
chgreqrec![StartTime] = DLookup("[tblSchedules].StartTime", "[tblSchedules].Employee = " & Employee And "[tblSchedules].Day = " & txtWeekDay)

Help with the code and and further tips (in English please:laugh:) about using this function would be appreciated!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Help with the code and and further tips (in English please:laugh:) about using this function would be appreciated!
If you are still not successful after reviewing the link provided, post back. The criteria part of this is what trips most people up, what with having to concatenate the bits into a statement with the proper syntax. Know also that you cannot use DLookup on more than one table, which is what you appear to be trying to do. You would have to bring separate tables into a query first.

FWIW, code is always a more complicated way to do what you're trying to do when you can run append, delete or update queries from a form (which is usually simpler).
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top