Creating one Query in Vba

mfaqueiroz

New Member
Joined
Sep 30, 2015
Messages
5
Hello :)

I'm creating one query on VBA with the following filters:
1.Date<Date1 of my query QA
2.Miliseconds < Milseconds of my query QA
3.State = State1 | | | | |
4.Tag=Tag1

I've write the following:


Set dbs = DBEngine(0)(0)
Set QA = dbs.OpenRecordset("A", DB_OPEN_DYNASET)

Data1 = CDate(QA.Fields(2).Value
ms1 = QA.A(3).Value
state1 = QA.Fields(7).Value
tag1 = QA.Fields(8).Value

Set Tb_Test = dbs.OpenRecordset("SELECT TabInst.[ID], TabInst.[date], TabInst.[ms], TabInst.[Instalação], TabInst.[Painel], TabInst.[Descrição], TabInst.[State], TabInst.[Tag], TabInst.[Visto] FROM TabInst WHERE [date] < #" & Data1 & "# And [ ms] < " & ms1 & " And [State] = '" & State1 & "' And [Tag] = '" & Tag1 & "' ORDER BY TabInst.[date], TabInst.[ ms];", DB_OPEN_DYNASET)

This isn't working, my question is:
-I'm comparing the dates and the ms in the right way?
-The date format is dd-mm-aaaa hh:mm:ss
-The ms are only numbers...i should put the "&?
-The state and Tag are text , I assume that the comparison is write the correct way...


Thank in advance for your help :)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
The SQL string looks like valid except that you have an extra space at the left side of the field name [ ms], in two places. correct that and try again.

Don't use Key-words and Function names for field names of table. You have a field name: Date in your SQL String.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,834
Messages
6,162,268
Members
451,758
Latest member
lmcquade91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top