Results 1 to 3 of 3
  1. #1
    lmahere is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    11

    Unhappy Type Mismatch error 13 on SetValue Macro

    Hi guys , I am trying to create a SetValue Macro Using an expression that calculates date of birth based on an ID number. The expression works when inserted in control source but because i want to save the value in the table from the form i opted for set value which giving me the type mismatch error and its happening with all my SetValue macros . Below is my SetValue action .



    Item=[Forms]![Students]![Date of Birth]
    Expression = CDate(Mid([Forms]![Students]![ID Number],3,2) & "/" & Mid([Forms]![Students]![ID Number],5,2) & "/" & Left([Forms]![Students]![ID Number],2))
    Last edited by lmahere; 04-14-2016 at 07:21 AM.

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I don't use macros, so this is a bit of a guess, but Access likes date values to be delimited by # marks, so try expressing the data just as a string without CDate:

    "#" & Mid([Forms]![Students]![ID Number],3,2) & "/" & Mid([Forms]![Students]![ID Number],5,2) & "/" & Left([Forms]![Students]![ID Number],2) & "#"

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    For the Imahere's information, CDate requires the string date to not only look like a date based on the user's regional settings, it must be delimited by # or double quotes (") - not single ('). As suggested, simplest is to do without the date conversion entirely, unless you need to actually change the data type so that you can do date comparisons. However, since you said it's happening to several macros, the problem probably is that you have the data type set incorrectly in the table field. CDate does more than make a date look like a date - it actually changes the data type, so the place you're keeping it has to be compatible.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Type 13 (Type Mismatch) error
    By sdel_nevo in forum Programming
    Replies: 5
    Last Post: 01-22-2016, 10:01 AM
  2. Replies: 1
    Last Post: 12-12-2013, 01:46 PM
  3. Replies: 7
    Last Post: 07-24-2013, 02:01 PM
  4. Replies: 1
    Last Post: 05-11-2012, 10:59 AM
  5. Type mismatch in condition embedded macro
    By geremore in forum Programming
    Replies: 3
    Last Post: 08-09-2011, 02:05 PM

Tags for this Thread

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