Type mismatch!!??

b0gdan

Me
Local time
Yesterday, 23:47
Joined
Oct 5, 2006
Messages
29
Hi all,
I have a problem with the following piece of code:

Private Sub cmdCautare_Click()
Dim strSQL As String, strOrder As String, strWhere As String
'Select Case Me.cmbTipVersus
'Case 1
'If Me.cmbTipVersus = "" Then
strSQL = "SELECT tblDosare.DosarID, tblDosare.DenumireDosar, tblDosare.CodDosar, tblDosare.DataDosar, tblInstante.Localitate, tblStadiu.Data, tblStadiu.Stadiu FROM tblInstante INNER JOIN (tblDosare LEFT JOIN tblStadiu ON tblDosare.DosarID = tblStadiu.Dosar) ON tblInstante.InstantaID = tblDosare.Instanta"
strWhere = "WHERE"
strOrder = "ORDER BY DosarID"
If IsNull(Me.txtDenumire) Or Me.txtDenumire = "" Then
Else
strWhere = strWhere & "(DenumireDosar) Like '*" & Me.txtDenumire & "*'"
End If
If IsNull(Me.cmbStadiu) Or Me.cmbStadiu = "" Then
Else
strWhere = strWhere & "(DenumireDosar) Like '" & Me.txtDenumire & "*' & " And " & (Stadiu) Like '" & Me.cmbStadiu & "*'"
End If
DoCmd.OpenForm "frmRezultateCautare", acNormal
Forms!frmRezultateCautare!lstRezultate.RowSource = strSQL & " " & strWhere & "" & strOrder
'End If
'End Select
End Sub

And on this line strWhere = strWhere & "(DenumireDosar) Like '" & Me.txtDenumire & "*' & " And " & (Stadiu) Like '" & Me.cmbStadiu & "*'"
i have an error message type mismatch. If i do the search only with the first text box the code works hjust fine but if i make the search w.r. with the second control (combo box cmbStadiu) the error appears. If anyone can help i will appreciate it.
Thank you all!
 
And " & (Stadiu) Like '" & Me.cmbStadiu & "*'"

should look like

And (Stadiu) Like '" & Me.cmbStadiu & "*'"

also is stadiu text or numeric. this is testing for text
 
Thanks but still doesn`t work and both stadiu an the other one are text type.
I think & "AND" & (Stadiu)=... is correct because is text concatening to get in SQL " Select xx Where x=... And y=... ". I don`t know what the problem is, thanks for the answer.
 
I'm not sure but on a previous line try:

strWhere = strWhere & "(DenumireDosar) Like *'" & Me.txtDenumire & "*'"
 
And " & (Stadiu) Like '" & Me.cmbStadiu & "*'" is definitley wrong

after the and you need to specifiy the field in the table so it has to with in the quotes.

And (Stadiu) Like '" & Me.cmbStadiu & "*'"
is likely to be correct. However is your combo box bound to a numeric value or a text value, because if you have a 2 column combo box, say, then you may be referncing the wrong column of the combo box

best thing to do is display strwhere in a msgbox to see what it looks like - if you are getting errors its definitely wrong!
 

Users who are viewing this thread

Back
Top Bottom