Advertisement

06.04.2008 at 12:45PM PDT, ID: 23458105
[x]
Attachment Details

3464 Data type mismatch in criteria expression?

Asked by Haze0830 in Microsoft Access Database, Visual Basic Programming, Microsoft Visual Basic.Net

Tags: VBA/VBS, Access 2007

I have this code below that I'm trying to use to build a conditional/dymanic query of a table. It works great until I input a number to search by. Then I get "3464 Data type mismatch in criteria expression"

My form is rudimentary right now, two fields "Wall" and "Code" - the Code will always be numeric. Intended result is that it returns records that match whatever combination of criteria are input into the fields. Like I said, it works great unless I enter a # to search by in the Code field.

I know it's got either something to do with formatting of the control in Access or in the code itself. I just can't seem to narrow it down or get it to agree. Help is appreciated. Thanks. Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
Function BuildSQLString(strSQL As String) As Boolean
Dim strWHERE As String
Dim ctl As Control
Dim i As Integer
For Each ctl In Me.Form.Controls
If ctl.ControlType = acTextBox Then
For i = 1 To Me.Form.Controls.Count
If Not IsNull(ctl) Then
If IsNumeric(ctl) Then 'This is a number
strWHERE = strWHERE & " And " & ctl.Name & " = " & ctl
ElseIf IsDate(ctl) Then 'This is a date
strWHERE = strWHERE & " And " & ctl.Name & " =#" & ctl & "#"
Else 'This is text
strWHERE = strWHERE & " And " & ctl.Name & "='" & ctl & "'"
End If
End If
Next i
strWHERE = strWHERE
End If
Next ctl
strSQL = "SELECT * FROM [Lot Specs]"
If strWHERE <> "" Then strSQL = strSQL & " WHERE " & Mid$(strWHERE, 6)
BuildSQLString = True
End Function
 
Private Sub cmdFind_Click()
 
On Error GoTo Err_Handler
Dim strSQL As String
Dim stDocName As String
Dim strMsg As String
Dim strCount As String
stDocName = "qrySearchForm"
 
If Not BuildSQLString(strSQL) Then
MsgBox "There was a problem building the string"
Exit Sub
End If
CurrentDb.QueryDefs(stDocName).SQL = strSQL
RefreshDatabaseWindow
strCount = DCount("*", stDocName)
strMsg = "There are " & strCount & " Records Found" & vbCrLf & vbCrLf & _
"Do You Want To View These Records?"
If MsgBox(strMsg, vbYesNo) = vbYes Then
DoCmd.OpenQuery stDocName, , acReadOnly
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Number & " " & Err.Description
Resume Exit_Handler
 
End Sub
[+][-]06.04.2008 at 01:27PM PDT, ID: 21713829

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 01:51PM PDT, ID: 21714034

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 01:54PM PDT, ID: 21714057

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 01:58PM PDT, ID: 21714091

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 02:06PM PDT, ID: 21714153

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.05.2008 at 07:50AM PDT, ID: 21720146

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Access Database, Visual Basic Programming, Microsoft Visual Basic.Net
Tags: VBA/VBS, Access 2007
Sign Up Now!
Solution Provided By: jmundsack
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.09.2008 at 09:10AM PDT, ID: 21744313

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.09.2008 at 09:49AM PDT, ID: 21744630

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628