Runtime Error 13 - Type Mismatch (1 Viewer)

jeran042

Registered User.
Local time
Today, 04:29
Joined
Jun 26, 2017
Messages
127
Im sure Im missing something so obvious, but cant seem to troubleshoot it. I am getting a type mismatch on the following code:

Code:
Private Sub Text2_Click()

Dim iCost_Center As Integer
Dim sCategory As String
Dim sWhere As String
Dim sFormName As String


iCost_Center = Me.txtCOST_CENTER
sCategory = Me.txtTemp_Month_Temp_Per
sWhere = "[COST_CENTER] = " & iCost_Center And "[CATEGORY] = " & "'" & sCategory & "'"   'This is the line throwing up the error
sFormName = "frm: Ledger Detail"


DoCmd.OpenForm sFormName, acViewNormal, , sWhere, , acDialog


End Sub

Can someone point out what I'm doing wrong? :banghead:
Very much appreciated!!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:29
Joined
Aug 30, 2003
Messages
36,125
I moved your post out of the moderated code repository forum.

For starters, the "And" needs to be inside the quotes; you have it outside.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:29
Joined
Feb 28, 2001
Messages
27,156
Paul is right.

That is also the cause of your type mismatch. Since the "AND" is not quoted, what you are doing is the expression

Code:
iCost_Center And "[CATEGORY] = "

where you are doing the AND of an integer and a string constant. That is your mismatch.
 

Users who are viewing this thread

Top Bottom