Results 1 to 8 of 8
  1. #1
    vojinb is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    18

    cannot update date in table

    Hy,
    I have a table having one date field formatted as short date "15.12.2011", and on a form text box formatted as short date format. When I click on text box calendar appears and I choose proper date, but when I want to update date in table via query it returns error.
    My query looks like:
    CurrentDb.Execute ("UPDATE category SET date=" & Forms![main form]!txtDate.Value)
    I don't see anything wrong but it keeps me returning error

    And If I use US format update works but with date 31.12.1899


  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    What happens if you run the update query outside of VBA? Does it work? Are you getting an error message?

  3. #3
    vojinb is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    18
    Hi
    when I run query:
    UPDATE kategorija SET datum="21.12.2011"
    then format of date works, but when I try to pick it from control on form gets error. Control is formatted ad date with calendar from side.

  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Because it is a date value, you need to surround the date value with # symbols.

  5. #5
    vojinb is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    18
    Hi, ive tried also to use #, but it insert wrong date , for example I choose 15.12.2011 from calendar, and after update in my table is date 12.30.1899 )

  6. #6
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    I just created a table (NewDates) with dates, a form with an unbound text box (qDate) and an update query.

    Here is the SQL statement and it ran perfectly:

    UPDATE NewDates SET NewDates.EndDate = [Forms]![frmTestSearch].[qDate];

    I haven't tried to put this into a VBA statement, but the main difference between yours and mine appear to be the quotation marks and the ampersand.

  7. #7
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Ok I got it to work off a command button on a form. Here is the code:

    Code:
    CurrentDb.Execute ("UPDATE NewDates SET NewDates.EndDate =#" & [Forms]![frmTestSearch].[qDate]) & "#"
    Need to have the update criteria surrounded by the # symbol
    Alan

    Crosspost: https://www.accessforums.net/showthr...ed=1#post93899
    Last edited by alansidman; 12-15-2011 at 02:24 PM. Reason: Crosspost duplication

  8. #8
    vojinb is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    18
    Thanks,
    It works ))
    Great!

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

Similar Threads

  1. cannot update date in table
    By vojinb in forum Import/Export Data
    Replies: 6
    Last Post: 12-15-2011, 02:23 PM
  2. Update date
    By BorisGomel in forum Forms
    Replies: 5
    Last Post: 09-20-2011, 03:15 PM
  3. query to update a date based on another date
    By tkendell in forum Access
    Replies: 3
    Last Post: 06-29-2011, 09:32 PM
  4. Replies: 1
    Last Post: 01-22-2011, 12:23 PM
  5. Update field in table after update on a subform
    By jpkeller55 in forum Queries
    Replies: 3
    Last Post: 09-30-2010, 08:02 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