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 > PC based Database Applications > Microsoft Access > Trouble deleting data in VBA based on criteria

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Mar 2012
Location: Blackstone, MA, USA
Posts: 5
Trouble deleting data in VBA based on criteria

I've been stuck on one small item for awhile and it's driviing me nuts. In short, I want to run a delete query in VBA to delete records containing a billing month that's greater that a precalculated current month. The source data from another system has the dates in text format, shown as (YYYY/MM).

Here's the statement:

Code:
mySQL = "DELETE * FROM [tblBillingData]" _
& "WHERE (((tblBillingData.[Billing Month]) > #" & PreCalcCurrentMonth & "#, ));"
DoCmd****nSQL mySQL

When it runs, it deletes everything from the table, not just the items where the billing month is greater than the current month.

All variables are declared properly and I can see the PreCalcCurrentMonth when I step through the codeAny suggestions?

Should I be evaluating each recordset individually?

Thanks,

Ed
Reply With Quote
  #2 (permalink)  
Old
Moderator
 
Join Date: Mar 2009
Posts: 5,129
The format of the data does not matter here. What's the data type of the column [Billing Month] and what's the Type of the variable PreCalcCurrentMonth?
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Mar 2012
Location: Blackstone, MA, USA
Posts: 5
Hi, both [Billing Month] and PreCalcCurrentMonth data types are String

If I do this is a regular MS Access query and use PreCalcCurrentMonth as a parameter which I key in at run time, it works.
Reply With Quote
  #4 (permalink)  
Old
Moderator
 
Join Date: Mar 2009
Posts: 5,129
Then the criteria should be:
Code:
"WHERE (((tblBillingData.[Billing Month]) > '" & PreCalcCurrentMonth & "'" ));"
The pound (or number) character (#) has a numeric code of 35, i.e. lower than any numeric or alphabetic character. In a string comparison, a string beginning with # will always be smaller than any alphanumeric string.
__________________
Have a nice day!
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Mar 2012
Location: Blackstone, MA, USA
Posts: 5
Great, thanks! It worked successfully once, but I've got more testing to do. Btw, you had an extra " at the end after the single '. Just in case someone else should need this, Thanks again!
Reply With Quote
  #6 (permalink)  
Old
Moderator
 
Join Date: Mar 2009
Posts: 5,129
You're welcome!
__________________
Have a nice day!
Reply With Quote
Reply

Tags
ms access vba

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On