Results 1 to 11 of 11
  1. #1
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150

    Data type mis match error

    Hi

    when i run the below code i get the error "Data type mismatch in criteria expression"

    Code:
    CurrentDb.Execute "Update tblUser SET Pdate = Now() WHERE ID = '" & Me.UserLogin & "'"
    Table Fields:
    1. Pdate = Date/Time
    2.UserLogin = Number

    how to avoid this error?

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    You have used text delimiters for loginID. Change it to

    Code:
    CurrentDb.Execute "Update tblUser SET Pdate = Now() WHERE ID = " & Me.UserLogin
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    use a query instead of sql. It eliminates a lot of these errors.

  4. #4
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150
    Hi Ridders

    Thanks alot mate. it worked.

    When i run the above code, after executing it i get the below message, how can ignore below message?

    Click image for larger version. 

Name:	Untitled.jpg 
Views:	18 
Size:	31.8 KB 
ID:	34309

  5. #5
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Oh no - the dreaded write conflict error...
    It can be one of the hardest to track down and you can't bypass it using error handling
    Nor should you ignore it

    Does it still happen if you:
    a) restart the app
    b) decompile & then compact
    c) are the only user

    If so, you need to identify the cause & fix it.
    I used to get this with a split database & a SQL server BE.
    On upsizing to SQL Server, I had neglected to set default values for boolean fields in several tables.
    This is an issue as unlike Access boolean fields can be null in SQL Server
    This confuses Access & triggered the write conflict in certain situations e.g. update queries
    The solution in my case was to set default values for all boolean fields in all tables
    I've never seen the error since.

    If that's not the issue in your case, you will need to track down the cause methodically.
    I would do so as a priority otherwise it is likely other issues will arise from this
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  6. #6
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150
    Hi ridders,

    i doesn't happen to me when
    a) restart the app
    b) decompile & then compact
    c) are the only user

    i shows when i run the update query only.

  7. #7
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I see nothing in the update query that would trigger it.
    Does it happen if you run that line on it's own rather than as part of a procedure?
    What about if you run a query with that code?

    If both still trigger it, look at the table design carefully. In fact do that first as it should be quick to check it for issues.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  8. #8
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150
    Hi Ridders


    instead of currentfb.execute cani use something like below?

    Code:
    StrSQL2= "Update tblUser SET Pdate = Date() WHERE ID = " & Me.UserLogin
    do you this will work?

  9. #9
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Yes you can use a sql statement like this:
    Code:
    CurrentDb.Execute strSQL
    Or
    Code:
    DoCmd.RunSQL strSQL
    However these won't solve your write conflict issue. You'll need to sort out what's causing that.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  10. #10
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150
    Hi Ridders

    i used below before the update statement, it eliminated the write conflict error.

    Code:
    DoCmd.RunCommand acCmdSaveRecord
    Thank you for your time and help.

  11. #11
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    If that's all it was, you were very lucky.
    If so, this would also have worked
    Code:
    If Me.Dirty Then Me.Dirty=False
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

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

Similar Threads

  1. Data type Error
    By Glenn_Suggs in forum Access
    Replies: 3
    Last Post: 01-25-2016, 11:30 AM
  2. Replies: 3
    Last Post: 05-31-2013, 04:32 PM
  3. Replies: 1
    Last Post: 05-11-2012, 10:59 AM
  4. Replies: 2
    Last Post: 03-18-2010, 08:24 PM
  5. data type mis match
    By cowboy in forum Programming
    Replies: 3
    Last Post: 03-12-2010, 11:54 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