If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > VBA Delete Using Date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-14-09, 07:28
cameron.scrimgeou cameron.scrimgeou is offline
Registered User
 
Join Date: Sep 2009
Posts: 12
VBA Delete Using Date

I have a piece of VBA which deletes a row from a linked table based on the data in the name column being 'John'...

CurrentDb.Execute "DELETE FROM TABLE WHERE NAME = 'John'"

This works fine but I now want to delete records with name = 'John' and where the date column is a specific date...

CurrentDb.Execute "DELETE FROM TABLE WHERE DATE_REPORTED = #01/07/2009 12:00:00# AND NAME = 'John'"

There is a record with the date and name 01/07/2009 12:00:00 and John but it doesnt seem to delete.

Must be something wrong with the way I am using the date?

Please Help.
Reply With Quote
  #2 (permalink)  
Old 09-27-09, 19:16
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
The date is ambiguous, ie. Is it 1st July 2009 or 7th January 2009? VBA will automatically assume US settings, so 7th January. If your table is in dd/mm/yyyy format then you can use the format function to return the correct date:
Date/Time: Return Dates in US #mm/dd/yyyy# format
Reply With Quote
  #3 (permalink)  
Old 09-30-09, 22:43
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
You can avoid worrying about date formats if you use query parameters. It also protects you against SQL injection.

Here's an MSDN article on how to do it.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On