Results 1 to 7 of 7
  1. #1
    Misterpokey is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2020
    Posts
    8

    Question Run-Time Error data type missmatch

    Good Day,

    You guys gave me some pointers on my Asset Database a couple of days ago and I thank you for the help. After making the changes I am running into an error that I am at a loss with. I keep getting a "Run-Time Error '3464': Data type mismatch in criteria expression" for the 'Update" and "Delete" buttons on my forum. The "Add" button works just fine in adding records to the table. I am assuming I am missing something in the code.

    I have attached print screens of the Table and the Form I put together and also the code will be below.


    Click image for larger version. 

Name:	Form.jpg 
Views:	9 
Size:	66.8 KB 
ID:	41259Click image for larger version. 

Name:	Table.jpg 
Views:	10 
Size:	117.7 KB 
ID:	41260

    Code:


    Private Sub cmdAdd_Click()


    'When we click on button Add there are two options
    '1. for insert
    '2. for update
    If Me.txtSerialNumber.Tag & "" = "" Then
    'this is for insert new
    'add data to table
    CurrentDb.Execute "INSERT INTO ToBeProcessed(SerialNumber, ITGNumber, FixedAssetTagNumber, AssetName, AssetType, Department, AccountString, DateDeployed) " & _
    " VALUES(" & Me.txtSerialNumber & ",'" & Me.txtITGNumber & "','" & _
    Me.txtFixedAssetNumber & "','" & Me.txtAssetName & "','" & Me.cbcAssetType & "','" & Me.cbcDepartment & "','" & Me.txtAccountString & "','" & txtDateDeployed & "')"

    Else
    'otherwise (Tag of txt store the Asset number of item to be modified
    CurrentDb.Execute "UPDATE ToBeProcessed " & _
    " SET SerialNumber=" & Me.txtSerialNumber & _
    ", ITGNumber='" & Me.txtITGNumber & "'" & _
    ", FixedAssetTagNumber='" & Me.txtFixedAssetNumber & "'" & _
    ", AssetName='" & Me.txtAssetName & "'" & _
    ", AssetType='" & Me.cbcAssetType & "'" & _
    ", Department='" & Me.cbcDepartment & "'" & _
    ", AccountString='" & Me.txtAccountString & "'" & _


    ", DateDeployed='" & Me.txtDateDeployed & "'" & _
    " Where SerialNumber=" & Me.txtSerialNumber.Tag

    End If




    'clear form
    cmdClear_Click


    'refresh data in list on form
    frmToBeProcessedSub.Form.Requery


    End Sub


    Private Sub cmdClear_Click()
    Me.txtSerialNumber = ""
    Me.txtITGNumber = ""
    Me.txtFixedAssetNumber = ""
    Me.txtAssetName = ""
    Me.cbcAssetType = ""
    Me.cbcDepartment = ""
    Me.txtAccountString = ""
    Me.txtDateDeployed = ""

    'focus on Serial Number Text Box
    Me.txtSerialNumber.SetFocus
    'set button edit to endable
    Me.cmdEdit.Enabled = True
    'change caption of button add to Add
    Me.cmdAdd.Caption = "Add"
    'clear tag on txtSerialNumber for reset new
    Me.txtSerialNumber.Tag = ""


    End Sub


    Private Sub cmdClose_Click()


    DoCmd.Close


    End Sub


    Private Sub cmdDelete_Click()
    'delete record
    'check existing selected record
    If Not (Me.frmToBeProcessedSub.Form.Recordset.EOF And Me.frmToBeProcessedSub.Form.Recordset.BOF) Then
    'confirm delete
    If MsgBox("Are you sure you want to delete this Asset?", vbYesNo) = vbYes Then
    'delete now
    CurrentDb.Execute "DELETE FROM ToBeProcessed " & _
    " WHERE SerialNumber=" & Me.frmToBeProcessedSub.Form.Recordset.Fields("Seri alNumber")
    'refresh data
    Me.frmToBeProcessedSub.Form.Requery
    End If
    End If
    End Sub


    Private Sub cmdEdit_Click()
    'check wether there exists data in list
    If Not (Me.frmToBeProcessedSub.Form.Recordset.EOF And Me.frmToBeProcessedSub.Form.Recordset.BOF) Then
    'get data to text box control
    With Me.frmToBeProcessedSub.Form.Recordset
    Me.txtSerialNumber = .Fields("SerialNumber")
    Me.txtITGNumber = .Fields("ITGNumber")
    Me.txtFixedAssetNumber = .Fields("FixedAssetTagNumber")
    Me.txtAssetName = .Fields("AssetName")
    Me.cbcAssetType = .Fields("AssetType")
    Me.cbcDepartment = .Fields("Department")
    Me.txtAccountString = .Fields("AccountString")
    Me.txtDateDeployed = .Fields("DateDeployed")
    'store Item Number of asset in Tag of txtItemNumb in case Number is modified
    Me.txtSerialNumber.Tag = .Fields("SerialNumber")
    'change caption of button add to Update
    Me.cmdAdd.Caption = "Update"
    'disable button edit
    Me.cmdEdit.Enabled = False
    End With
    End If
    End Sub



    Thanks all! I am trying to learn all this on the fly.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    the error message is clear - you are mixing datatypes.
    For example you have serialnumber as short text datatype, but are trying to provide a numeric datatype here

    Code:
    " VALUES(" & Me.txtSerialNumber & ",
    and here

    Code:
    " WHERE SerialNumber=" & Me.frmToBeProcessedSub.Form.Recordset.Fields("SerialNumber")
    with a field name like 'SerialNumber' I would expect the value to be numeric, so I suspect your field datatype is incorrect. If it is not numeric then the name is misleading - 'ABC' is not a number (which from the above code you think it should be) so I would rename as SerialCode or similar

  3. #3
    Misterpokey is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2020
    Posts
    8
    I can certainly change the name, the reason why I have it as short text and not numeric is because the Serial Numbers of the assets are alphanumeric. It seems based on what you said there is a alphanumeric datatype syntax i should be using? I had that suspicion but I don't have much experience with coding.

    Thanks!

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    abc123 is text, 123 is numeric so you need to include the quotes as per text. There is not an alphanumeric datatype

  5. #5
    Misterpokey is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2020
    Posts
    8
    Quote Originally Posted by Ajax View Post
    abc123 is text, 123 is numeric so you need to include the quotes as per text. There is not an alphanumeric datatype
    Sorry Ajax, could you give me an example of where to put the quotes in the code? These basic code stuff is pretty new to me.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    as you have here

    " VALUES(" & Me.txtSerialNumber & ",'" & Me.txtITGNumber & "','" & _



  7. #7
    Misterpokey is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2020
    Posts
    8
    OK got it! All working now.

    Thanks for the help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 07-25-2019, 05:49 PM
  2. Type Expression Missmatch
    By MdHaziq in forum Queries
    Replies: 1
    Last Post: 01-17-2018, 03:44 AM
  3. Error 13 (Type Missmatch) problem
    By sdel_nevo in forum Programming
    Replies: 4
    Last Post: 01-31-2016, 06:54 AM
  4. Run-time error 13 type Mismatch
    By Jaron in forum Programming
    Replies: 2
    Last Post: 09-13-2013, 02:33 PM
  5. Error: Run-time error '13' Type mismatch
    By uronmapu in forum Access
    Replies: 1
    Last Post: 09-07-2012, 05:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums