Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2007, 05:46 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default error 3464 'data type mismatch in criteria express

Hi,

I have a from that tells me the next error when I try to run the code of the only action button on the form:

Data type mismatch in criteria expression (error number 3464)

The code that the button runs on to is:

Private Sub cmdCheckOut_Click()
On Error GoTo Err_cmdCheckOut_Click

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim sSQL As String
Dim intNumber As Long
Dim varItem As Variant

If Me.lstCheckOut.ItemsSelected.Count = 0 Then
    MsgBox "Er werd geen keuze gemaakt uit de lijst." & vbCrLf & _
        "Er werd dus niemand uitgeschreven." & vbCrLf & vbCrLf & _
        "Aucun choix n'a été effectué." & vbCrLf & _
        "Personne n'a donc été désinscrit.", vbExclamation, "CobelAdmin"
    Exit Sub
Else
    For Each varItem In Me.lstCheckOut.ItemsSelected
        intNumber = Me.lstCheckOut.Column(0)
        sSQL = "SELECT tblOpvolgingBezoekers.Autonumber, tblOpvolgingBezoekers.DateTimeOut, tblOpvolgingBezoekers.CheckOutDoor " & _
            "FROM tblOpvolgingBezoekers " & _
            "WHERE (((tblOpvolgingBezoekers.Autonumber)= " & Chr(34) & intNumber & Chr(34) & "));"
        Set db = Application.CurrentDb()
        Set rst = db.OpenRecordset(sSQL, dbOpenDynaset)

        While Not rst.EOF
            rst.Edit
                rst("DateTimeOut") = Now()
                rst("CheckOutDoor") = sAanlog
            rst.Update
            rst.MoveNext
        Wend

        rst.Close
        Set rst = Nothing
        Set db = Nothing
    Next varItem
End If

Exit_cmdCheckOut_Click:
    Exit Sub

Err_cmdCheckOut_Click:
    MsgBox Err.Description & " Error number = " & Err.Number
    Resume Exit_cmdCheckOut_Click

End Sub

Does anyone know why I get this error? To me the code seems OK...

 
Old May 2nd, 2007, 12:28 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

If you are taking a PK into intNumber, then declare the variable like this:

Dim intNumber As Integer

Did that help?





mmcdonal
 
Old May 3rd, 2007, 04:23 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I changed the dim intNumber to integer and I still got the same error.

I then removed the chr(34) on each side of the intnumber in the sql and it seems to work now...

Thanks

 
Old May 3rd, 2007, 06:45 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Okay, the reason that you were getting the error is that your code, with the Chr(34) looked like this:

"WHERE (((tblOpvolgingBezoekers.Autonumber)= " & " & intNumber & " & "));"

In fact, when you use numbers, you do not put quotes (double or single) around your values. So it should looke like this:

"WHERE (((tblOpvolgingBezoekers.Autonumber)= " & intNumber & "));"

Although, I would write it like this:

"WHERE [Autonumber] = " & intNumber





mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
data type mismatch in criteria expression coreyjustin Classic ASP Basics 1 December 10th, 2007 06:49 PM
data type mismatch in criteria expression xigler Access 3 March 23rd, 2007 08:54 AM
Data Type Mismatch Error in Criteria Expression mmcdonal Access VBA 2 March 1st, 2007 05:18 PM
Data type mismatch in criteria expression. imercha Classic ASP Basics 3 November 23rd, 2006 11:09 AM
Data type mismatch in criteria expression. kalchev ASP.NET 2.0 Professional 5 April 11th, 2006 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.