storing SQL results in a var

shrive22

Board Regular
Joined
Jun 10, 2002
Messages
120
Does anyone know how to store the results from an sql statement in vb code in a variable. The resluts from the query are going to change based upon what the user chooses on my form??

thanks
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Look up the database functions in Help (DMax, DCount, DSum, etc.). I'm sure that they will be what you're looking for. If you don't think that they are, please post example SQL.

HTH,

Russell
 
Upvote 0
this is what I would like

dim x as string
x = "SELECT field1 FROM table"

somehow i want to get the results from the query into a variable

my sql statement will only be returning on value because I will have a where clause that limits it to the primary key fieild.

thanks for the help
 
Upvote 0
If your WHERE clause will limit it to one record, then you can use DMax. Give it a try - if it doesn't work, show me what you tried and I'll see if I can help.

-rh
 
Upvote 0
How would the dmax function work when I dont want the maximum value of the domain i just want to test the expression
??
 
Upvote 0
Because if your WHERE clause will only return one record, then the MAX of that record will be...yep, that one record! :-D
 
Upvote 0
So say you have something like this for your query:

SELECT fldTotal FROM tblOne WHERE fldMyDate = #04/09/2003#

If this returns one record, then you could use DMax like this:

varSomething = DMax("[fldTotal]", "tblOne", "[fldMyDate] = #04/09/2003#")

Make sense? Hope so,

Russell
 
Upvote 0

Forum statistics

Threads
1,223,549
Messages
6,172,988
Members
452,496
Latest member
VC777

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