View Full Version : Run-Time Error '3464' Data Type Mismatch In Criteria Expression


nick.tait
05-27-2009, 08:56 PM
Hi all
Can anyone help with this error message that keeps occuring. 'Run-Time error 3464 Data Type Mismatch In Criteria Expression.' It happens in my code below in the line highlighted in red. Thanks in advance

Option Compare Database
Option Explicit

Private Sub Custodian_History_Form_Enter()

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim strQuery1 As String
Dim strQuery2 As String

Dim nod As Object
Dim strNode1Text As String
Dim strNode2Text As String
Dim strVisibleText As String

Dim strMessage As String
Dim intVBMsg As Integer

Set db = CurrentDb()
strQuery1 = "select DISTINCT AssetNumber from [Asset Master]"
With Me![Custodian History Form]
Set rs = db.OpenRecordset(strQuery1) ', dbOpenForwardOnly)
Do Until rs.EOF
Debug.Print rs![AssetNumber]
strNode1Text = StrConv("Level1" & rs![AssetNumber], _
vbLowerCase)
Set nod = .Nodes.Add(Key:=strNode1Text, Text:=rs![AssetNumber])
nod.Expanded = False

strQuery2 = "select DISTINCT AssetNumber, [Asset Name] from [Asset Master] where [AssetNumber] = '" & nod.Text & "'"
Set rs2 = db.OpenRecordset(strQuery2)
Do Until rs2.EOF
strNode2Text = StrConv("Level2" & rs2![Changes In Asset], vbLowerCase)
strVisibleText = rs2!AssetNumber
'if modelname is null, will have problem
If IsNull(rs2!AssetNumber) Then
MsgBox "number is null"
strVisibleText = "No Name"
End If
Set nod = .Nodes.Add(relative:=strNode1Text, relationship:=tvwChild, _
Key:=strNode2Text, Text:=strVisibleText)
rs2.MoveNext
Loop
rs2.Close
rs.MoveNext
Loop
rs.Close
End With

End Sub

pbaldy
05-27-2009, 09:31 PM
If the data type of AssetNumber is numeric:

strQuery2 = "select DISTINCT AssetNumber, [Asset Name] from [Asset Master] where [AssetNumber] = " & nod.Text

nick.tait
05-27-2009, 09:38 PM
Thank you SOOOO much Paul
i ran it and found a few more errors which i fixed however go stuck on a line which i have had troubles with for a while. i cant seem to get it right. Its in red below.

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim strQuery1 As String
Dim strQuery2 As String

Dim nod As Object
Dim strNode1Text As String
Dim strNode2Text As String
Dim strVisibleText As String
Dim strMessage As String
Dim intVBMsg As Integer

Set db = CurrentDb()
strQuery1 = "select DISTINCT AssetNumber from [Asset Master]"
With Me![Custodian History Form]
Set rs = db.OpenRecordset(strQuery1) ', dbOpenForwardOnly)
Do Until rs.EOF
Debug.Print rs![AssetNumber]
strNode1Text = StrConv("Level1" & rs![AssetNumber], _
vbLowerCase)
Set nod = .Nodes.Add(Key:=strNode1Text, Text:=rs![AssetNumber])
nod.Expanded = False

strQuery2 = "select DISTINCT AssetNumber, [Asset Name] from [Asset Master] where [AssetNumber] = " & nod.Text
Set rs2 = db.OpenRecordset(strQuery2)
Do Until rs2.EOF
strNode2Text = StrConv("Level2" & rs2![Asset Name], vbLowerCase)
strVisibleText = rs2!AssetNumber
'if modelname is null, will have problem
If IsNull(rs2!AssetNumber) Then
MsgBox "number is null"
strVisibleText = "No Name"
End If
Set nod = .Nodes.Add(relative:=strNode1Text, relationship:=tvwChild, _
Key:=strNode2Text, Text:=strVisibleText)
rs2.MoveNext
Loop
rs2.Close
rs.MoveNext
Loop
rs.Close
End With
End Sub