PCFIX-IT
asked on
Access 2007 DLookup Autonumber Type mismatch Error
Hello Experts!
This is an application for employees to schedule a conference room for meetings. There are several conference rooms; the forms allows the user to pick a conference room from a combo box, there is a list box in turn that lists the scheduled dates for that conference room. When the user clicks on a date, it populates text boxes on the side with the information of who scheduled it, when it was scheduled, etc.
My problem is displaying the employee name. I have an Employees table and a Data table. Each employee has an ID on the Employees table, the Data table stores that ID under the employee field. The ID itself is a regular Autonumber (Long integer). I've included my code; I don't understand why I keep getting type mismatch!
This is an application for employees to schedule a conference room for meetings. There are several conference rooms; the forms allows the user to pick a conference room from a combo box, there is a list box in turn that lists the scheduled dates for that conference room. When the user clicks on a date, it populates text boxes on the side with the information of who scheduled it, when it was scheduled, etc.
My problem is displaying the employee name. I have an Employees table and a Data table. Each employee has an ID on the Employees table, the Data table stores that ID under the employee field. The ID itself is a regular Autonumber (Long integer). I've included my code; I don't understand why I keep getting type mismatch!
Private Sub lboDates_Click()
Dim lngEmployee As Long
lngEmployee = DLookup("[Employee]", "[tblData]", "[Room]='" + Me.cboRoom.Column(1) + "'") 'This DLookup works fine, returns a long with the correct Employee ID
Dim strEmployeeName As String
strEmployeeName = DLookup("[FirstName]", "[tblEmployees]", "[ID]=" + lngEmployee) 'Here is where the error occurs. I've tried adding single quotes before and after, but that still won't do anything.
MsgBox (strEmployeeName) 'This is just a test MsgBox to see if it works. I always get the error before getting to this point.
End Sub
ASKER
Thanks for the quick reply; I tried that and I get the same "Run-time Error '13' Type mismatch"
I think if the problem was that the record is null I'd be getting a Null Value error; I think it has to do with the Autonumber for some reason but that might be me being stubborn.
I think if the problem was that the record is null I'd be getting a Null Value error; I think it has to do with the Autonumber for some reason but that might be me being stubborn.
ok, should have been
If IsNull(strEmployeeName) Then
MsgBox "Cannot find the employee First Name for ID = " & lngEmployee, vbOkOnly
Else
MsgBox strEmployeeName
End If
If IsNull(strEmployeeName) Then
MsgBox "Cannot find the employee First Name for ID = " & lngEmployee, vbOkOnly
Else
MsgBox strEmployeeName
End If
ASKER
Thanks again for the quick reply Arthur,
That code still gives me the same Error as the other; right now the data in my tables is really limited as it's only test data; I know the ID and First Names I'm looking for exist and the ID is being picked up correctly.
The issue is not that it returns null values, it's the the ID field on the tblEmployees table keeps telling me there's a type mismatch even though I'm using a Long Integer for the DLookup.
That code still gives me the same Error as the other; right now the data in my tables is really limited as it's only test data; I know the ID and First Names I'm looking for exist and the ID is being picked up correctly.
The issue is not that it returns null values, it's the the ID field on the tblEmployees table keeps telling me there's a type mismatch even though I'm using a Long Integer for the DLookup.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window