Results 1 to 5 of 5
  1. #1
    VariableZ's Avatar
    VariableZ is offline Partially Knowledgeable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Georgia, USA
    Posts
    40

    "Date" in VBA Translates to "2010-06-22" Instead of Today's Date

    Windows7 64bit


    Access 2010 32bit

    I have a very odd problem. When trying to open a report that worked wonderfully last week, there are suddenly no results. I discovered the reason was that somehow DATE is getting translated as 2010-06-22 instead of 2012-03-13, which is today's date. I tried "=Date()" in the control source of a control and that worked properly. I changed the date on my computer, and the report still translates Date as 2010-06-22. The date on the server that the database is held on is correct. I've moved the database to my local machine and the problem persists. The code is below.

    DoCmd.OpenReport "rptLotData", acViewReport, , "([qryLotDataConglomerateWithTotals].[FormattedDate] Between #" & Date & "# And #" & DateAdd("m", -1, Date) & "#) And ([FirstOfModel] Like ""*" & [VINCodeReportSortByUnitField] & """" & " Or [FirstOfModel] Like """ & [VINCodeReportSortByUnitField] & " *"")"

    I've gotten around it by making a control named TodayField with control source "=Date()" and changing Date to [TodayField] in the VBA, but that doesn't seem like it should be a necessity. Any ideas?

  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,521
    My guess is that you have a field in the table named "Date" and Access is confused as to which you want. If so, you're seeing why we don't recommend using Date as a field name. This would be a workaround:

    DateAdd("m", -1, VBA.Date)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    You might want to keep this link handy. It has a listing of "Reserved Words." Avoid using these.

    http://office.microsoft.com/en-us/ac...010030643.aspx

  4. #4
    VariableZ's Avatar
    VariableZ is offline Partially Knowledgeable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Georgia, USA
    Posts
    40
    Sadly, I do have a field named 'Date', but I can't do anything about that since I didn't design the SQL database I have to pull my data from . I don't understand why it worked until this week, but it looks like suddenly Access decided that the field took precedence over the reserved name. Maybe changing to daylight savings time made it grouchy. It always makes me grouchy. Anyway, thanks for the VBA.Date. That worked.

    - Zohar S.E.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    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. Replies: 0
    Last Post: 02-20-2012, 04:57 PM
  2. Replies: 2
    Last Post: 11-04-2011, 02:45 AM
  3. Replies: 16
    Last Post: 07-22-2011, 09:23 AM
  4. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM
  5. Access Date/Time....I need a "generic" date.
    By beastmaster in forum Access
    Replies: 2
    Last Post: 12-29-2005, 12:55 PM

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