CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2010
    Posts
    42

    Data Type Mismatch in criteria expression

    when i save a record to access through error
    Run time error - Data Type Mismatch in criteria expression
    and when i go to debug...it directs to ".Open sSQL, sConnection, adOpenKeyset, adLockOptimistic" to this.
    Please sugesst

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Data Type Mismatch in criteria expression

    There is a lot of discussions about this error message:
    https://www.google.com/search?source...sion&gs_htsa=1
    Did you look at at least some of them?
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Data Type Mismatch in criteria expression

    Data Type mismatch means that one or more of your data types in the query does not match what is in the database. This happens when you try to apply a numeric value to a text field or a text value to a numeric field or non date value to a date field.

    Simple problem that you should be able to resolve but if you can't then the first step is to show us the query and would also help to know what types of fields are in the db in question
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Data Type Mismatch in criteria expression

    Show your query and table structure, as DM said

  5. #5
    Join Date
    Sep 2010
    Posts
    42

    Re: Data Type Mismatch in criteria expression

    Code:
    Private Sub cmdSave_Click()
    
    Dim cnuser As New ADODB.connection
    Dim rsuser As New ADODB.Recordset
    
    If sempty(txtFulNa.Text) = True Then Exit Sub
    If sempty(txtFan.Text) = True Then Exit Sub
    If sempty(txtEdate.Text) = True Then Exit Sub
    If sempty(txtShaha.Text) = True Then Exit Sub
    If sempty(txtSeno.Text) = True Then Exit Sub
    If sempty(txtFisNa.Text) = True Then Exit Sub
    If sempty(txtSecNa.Text) = True Then Exit Sub
    'If sempty(txtLasNa.Text) = True Then Exit Sub
    If sempty(txt1stID.Text) = True Then Exit Sub
    If sempty(txtExpDate.Text) = True Then Exit Sub
    If sempty(txtMob.Text) = True Then Exit Sub
    If sempty(txtChq.Text) = True Then Exit Sub
    If sempty(Combo1.Text) = True Then Exit Sub
    If sempty(Combo3.Text) = True Then Exit Sub
    If sempty(txtPrn.Text) = True Then Exit Sub
    
    Call connection(cnuser, App.Path & "\Commissions.mdb", "endromida")
    'Call connection(cnuser, "\\mika\medrar\Commissions.mdb", "endromida")
    Call Recordset(rsuser, cnuser, "SELECT * FROM commi_cus")
    
    
    With rsuser
    .AddNew
    Call shasta
    .Fields!funa = txtFulNa.Text
    .Fields!Sha_no = txtShaha.Text
    .Fields!Edate = txtEdate.Text
    .Fields!tr_no = txtSeno.Text
    .Fields!fami_na = txtFan.Text
    .Fields!first_na = txtFisNa.Text
    .Fields!sec_na = txtSecNa.Text
    If !last_na <> " " Then
     .Fields!last_na = txtLasNa.Text
     End If
    .Fields!cus_id = txt1stID.Text
    .Fields!cus_mo = txtMob.Text
    .Fields!exp_date = txtExpDate.Text
    .Fields!cus_mo = txtMob.Text
    .Fields!ch_no = txtChq.Text
    .Fields!ba = Combo1
    .Fields!tran_co = Combo3
    .Fields!pro_na = txtPrn.Text
    .Fields!sta = txtstat.Text
    .Update
    End With
    
    MsgBox "Successfully Saved.", vbInformation
    Call cmdRePrint_Click
    
    Call clear
    
    Set cnuser = Nothing
    Set rsuser = Nothing
    
    End Sub
    When i use Save...
    it will debug to
    Code:
    Public Sub Recordset(ByRef sRecordset As ADODB.Recordset, ByRef sConnection As ADODB.connection, ByVal sSQL As String)
    With sRecordset
    .CursorLocation = adUseClient
    .Open sSQL, sConnection, adOpenKeyset, adLockOptimistic
    End With
    End Sub
    Name:  untitled1.JPG
Views: 2179
Size:  62.8 KB

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Data Type Mismatch in criteria expression

    Are you sure that is where the error is? The message indicates a where clause but none exists in the code you have shown
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured