Results 1 to 4 of 4
  1. #1
    Douglasrac is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    92

    Question Data type mismatch in criteria expression

    Hi,



    I have the following problem:
    I have a button in a form that suppose to open another form, coping a number and pasting in the new form field.
    It works perfectly, but only one time. If the new form have data on it, it doesnt work. The error is: Data type mismatch in criteria expression

    Here is the code of the button:

    Code:
    Private Sub AbrirDadosdosCondutores_Click()
    
    On Error GoTo Err_AbrirDadosdosCondutores_Click
    
    	Dim stDocName As String
    	Dim strCriteria As String
    
    strCriteria = "[N do Seguro] = """ & Me.[N do Seguro] & """"
    
    DoCmd.OpenForm "Dados dos Condutores", _
    	WhereCondition:=strCriteria, _
    	WindowMode:=acDialog, _
    	OpenArgs:=(Me.[N do Seguro])
    
    Exit_AbrirDadosdosCondutores_Click:
    	Exit Sub
    	
    Err_AbrirDadosdosCondutores_Click:
    	MsgBox Err.Description
    	Resume Exit_AbrirDadosdosCondutores_Click
       
    End Sub
    I think the code should add something that says: open in a new record. Probably is trying to open the form, and the form opens showing the first record. As Access is unable to change the primary key, since it has a relationship with other tables, so I get the error.

    How can I make the button open a form in a new record?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    If that field is numeric you have the wrong syntax:

    BaldyWeb wherecondition
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Douglasrac is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    92

    Smile

    Quote Originally Posted by pbaldy View Post
    If that field is numeric you have the wrong syntax:

    BaldyWeb wherecondition
    Thank you. That solved the problem.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. type mismatch in expression
    By lilg1924 in forum Database Design
    Replies: 3
    Last Post: 10-06-2010, 01:37 AM
  2. data type mismatch in criteria expression
    By broecher in forum Access
    Replies: 4
    Last Post: 09-10-2010, 08:29 AM
  3. Data type mismatch in criteria expression
    By shexe in forum Queries
    Replies: 2
    Last Post: 09-01-2010, 12:47 PM
  4. Type mismatch in expression /Query
    By Brian62 in forum Queries
    Replies: 4
    Last Post: 04-22-2010, 10:00 AM
  5. Replies: 4
    Last Post: 10-26-2009, 05:27 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