Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Check Syntax Of SQL Select Statement In Access VBA Code, Access 2007

$
0
0
I have added a text box on my EmpDate form to display the Employee Name. The field is called EmpName. I have a relationship set up between the EmpDate table and the Employees table connected by the EmpID field. The EmpName is stored in the Employees table.

When I do the data entry with the EmpDate form the name displays fine.

When I use the Search Button I do not get the results I want.

See Attachment for Screen Captures.

Here is my code:

Form_EmpDate.RecordSource = "Select * from EmpDate where [EmpDate].DateWorked = " & _
Format(Me!txtSearchDateWorked, "\#mm\/dd\/yyyy\#") & _
" And [EmpDate].EmpID = " & Me!txtSearchEmpID


I tried the following code:

Form_EmpDate.RecordSource = "Select * from EmpDate, Employees where [EmpDate].DateWorked = " & _
Format(Me!txtSearchDateWorked, "\#mm\/dd\/yyyy\#") & _
" And [EmpDate].EmpID = " & Me!txtSearchEmpID

And this code almost works (the Employee Name displays) but now the EmpID doesn’t display correctly and the record count at the bottom gives an error.

I have attached the database and screen captures.

I know this must be fairly easy to do so if someone could take a look I would appreciate it.

Attached Files
File Type: zip JobCosting - Copy.zip (307.7 KB)
File Type: pdf Display name on the form.pdf (297.9 KB)

Viewing all articles
Browse latest Browse all 13329

Trending Articles