Results 1 to 8 of 8
  1. #1
    jimmy_bones is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    6

    Data Mismatch Error For Date Field

    Any idea what the problem here is? I keep getting a Data type miismatch error with this line:






    Code:
    "WHERE [Node Name] = '" & [Node Name].Value & "'" And "[Record Creation date] = '" & maxDate & "'" & _
    Code:
    
    

    The date part is causing the problem. I tried it like this too:





    "[Record Creation date] = #" & maxDate & "#'





    The maxDate variable is type Date. THe [Record Creatoin Date] field is dateTime.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Date and DateTime type fields are the same and YES the delimitor for dates is the octothorpe (#) and not a tick (') or quote (").

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You also have quotes in the wrong place:
    You have:
    Code:
    "WHERE [Node Name] = '" & [Node Name].Value & "'" And "[Record Creation date] = '" & maxDate & "'" & _
    should be:
    Code:
    "WHERE [Node Name] = '" & [Node Name] & "' And [Record Creation date] = #" & maxDate & "#" &
    " .VALUE" is the default property and is not required (but doesn't hurt)

    Also note that you shouldn't use spaces in object names. See
    http://access.mvps.org/access/tencommandments.htm

  4. #4
    jimmy_bones is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    6
    Thanks. That seemed to solve the first problem but here's another. As in the code above, I'm using the max date from field [Record Creation Date] as part of the criteria to populate a form. Here is a sample date as it would appear in the database:

    2012-09-04 17:39:30.270

    But when I use this code to get the max date:

    Code:
    maxDate = DMax("[Record Creation Date]", "[dbo_Node Opt Birth Certificate]", "[Node Name] = '" & daNode & "' ")
    the end result looks like this:

    9/4/2012 5:39:30 PM

    So when I run this code to open and populate the new form:
    Code:
    DoCmd.OpenForm "Node Opt Birth Certificate - Field", , , "[Node Name] = '" & Me.[Node Name].Value & "' AND [Record Creation Date] = #" & maxDate & "#"
    I get nothing. I assume this is because the VB doesn't consider these to be matching values because of the different formats. Is there a simple way to reformat one or the other so they're compatible?

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Perhaps this link will supply a better understanding of the DateTime field: http://support.microsoft.com/kb/q130514/en-us

  6. #6
    jimmy_bones is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    6
    I ended up trying this. The SQL works fine in SQL Server but I get an error message about the "convert" function when I try to run it in VBA via Docmd.RunSQL:

    Code:
    DoCmd.RunSQL "UPDATE [dbo_Node Opt Birth Certificate] SET [Record Creation Date VBA Format] = left(convert(varchar,[record creation date],109),LEN(convert(varchar,[record creation date],109))-6)+' '+right(convert(varchar,[record creation date],109),2) WHERE [Record Creation Date VBA Format] is NULL"

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I don't believe VBA includes the "Convert" instruction and since I don't know what it does in SQL I'm at a loss to assist at this point. I would guess that the [Record Creation Date VBA Format] field appears to be a string field though.

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Will there be records that match down to the second?

    It looks like this is a date/time from SQL Server : 2012-09-04 17:39:30.270 ?? Access chokes on the ".270" part. In Access you can convert the date/time to just the date by using the Int() function.
    Code:
    maxDate = DMax("[Record Creation Date]", "[dbo_Node Opt Birth Certificate]", "[Node Name] = '" & daNode & "'")
    maxDate = maxDate = Int(maxDate)
    You might try: (untested)
    Code:
    maxDate = DMax("[Record Creation Date]", "[dbo_Node Opt Birth Certificate]", "[Node Name] = '" & daNode & "'")
    'convert to date only
    maxDate = Int(maxDate)
    
    DoCmd.OpenForm "Node Opt Birth Certificate - Field", , , "[Node Name] = '" & Me.[Node Name].Value & "' AND Int([Record Creation Date]) = #" & maxDate & "#"

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

Similar Threads

  1. Data type mismatch error
    By Tomfernandez1 in forum Programming
    Replies: 5
    Last Post: 10-05-2012, 07:27 AM
  2. Data type mismatch error
    By nigelbloomy in forum Programming
    Replies: 1
    Last Post: 08-01-2012, 09:19 AM
  3. Replies: 1
    Last Post: 05-11-2012, 10:59 AM
  4. Data Validation error on Update - date field
    By TinaCa in forum Programming
    Replies: 6
    Last Post: 09-14-2011, 04:59 PM
  5. Data Mismatch Error
    By sneupane in forum Access
    Replies: 5
    Last Post: 03-15-2010, 08:17 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