By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

Set a Variable in VBA to be Used in SQL

P: 20
Hi, everyone

So this is really simple,

I have an Access Table called "BDAXA", where there are many records, and a column called "Date".

I use an imput box called (DAT) where I ask the user an especific month to generate a query in a format "mmyyyy", so lets say the user writes 022010, then DAT = 022010,

I need to know how can I use that variable (DAT) in the sql languaje
Expand|Select|Wrap|Line Numbers
  1. strsql = SELECT BDAXA.Fecha
  3. WHERE (((BDAXA.Date)=DAT));
Feb 11 '10 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 903

Expand|Select|Wrap|Line Numbers
  1. strsql = "SELECT BDAXA.Fecha FROM BDAXA WHERE (((BDAXA.Date) = #" & DAT & "# ));"
Feb 11 '10 #2

P: 20
Thanks so much mshmyob, you are really kind thanks for your answer, thanks thanks thanks, see ya
Feb 11 '10 #3

Expert Mod 15k+
P: 31,494
That will often work but not always.

Check out Literal DateTimes and Their Delimiters (#) for a fully portable solution.
Feb 12 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.