Please help. SQL Problem giving a ComboID

Lestatos

Registered User.
Local time
Today, 15:54
Joined
Oct 22, 2013
Messages
16
[SOLVED]Please help. SQL Problem giving a ComboID

Good evening dear programers.
Running the code below :
Code:
Private Sub Command299_Click()

Dim selection As String
Dim sname As String
If IsNull(Me.cmbWorkerNameReport.Column(0)) Then
MsgBox ("Choose Worker !")
Exit Sub
End If
Dim checkvar As Integer

checkvar = DLookup("Emp_ID", "tbl_Employees_General_Info", "Emp_ID = " & Me.cmbWorkerNameReport.Column(0))

sname = DLookup("Emp_First_Name", "tbl_Employees_General_Info", "Emp_ID = " & Me.cmbWorkerNameReport.Column(0)) & " " & DLookup("Emp_Last_Name", "tbl_Employees_General_Info", "Emp_ID = " & Me.cmbWorkerNameReport.Column(0))

selection = "SELECT Emp_First_Name, Emp_Last_Name , Emp_Notes " _
& "From tbl_Employees_General_Info " _
& "WHERE (((Emp_ID) = '" & checkvar & " ')) "

CreateDynamicReport selection, sname

End Sub
I get the following error : Runtime Error '3464' : Data type mismatch in criteria expression .
I am aware that this comes from the expression after WHERE statement , but my problem is that I tried getting the checkvar value by Dlookup , me.CmbName.Value , me.CmbName.Column(0) - where 0 is the column for Emp_ID , and I always get the same mistake . Where is the key to solve this ? :( I have already dimmed checkvar as Integer . I am sure that Emp_ID is defined in its table as AutoNumber............
Hope I formuled my question correct.
Best regards .

P.S -> J.F.Y.I CreateDynamicReport is a public function that creates and opens a report with a "Title" = sname and fields from the selection variable .
 
Last edited:
Use MsgBox statements to show what you are getting in the checkvar AND sname variables as a diagnostic. If in fact the EMP_ID is an Aurtonumber then you will want to change this:
& "WHERE (((Emp_ID) = '" & checkvar & " ')) "
...to...
& "WHERE (((Emp_ID) = " & checkvar )) "
...and an Autonumber is a Long Integer, not just an Integer.
 
RuralGuy - Thank you !
That was really usefull . I changed the variable type (checkvar) to Long and the removed the single brackets . Then the CreateDynamicReport function just did its job without any mistakes .
If we were at the pub now you have one Jack bottle from me ! :)
My best regards.
Hope this also will help other users of the forum .
 

Users who are viewing this thread

Back
Top Bottom