PDA

View Full Version : Getting a result of a query



Asi
11-03-2010, 12:17 PM
Hi

Maybe I am asking a basic question but still..
I want a text box to automatically get a value according to values that were selected on other Combo Boxes.
Basically what I need is to run:
select max(col1) from T1 where col2=Me!ComBoBox1 and col3=Me!ComboBox2

get the returned value and set the text box with the returned value + 1.

The question is what is the correct syntax in VBA to do this ?

Thanks
Asi

Imdabaum
11-03-2010, 12:39 PM
Have you tried...


=DLookup("Max(col1)", "[T1]", "[Col2] = " & Me!ComboBox2) +1

Asi
11-03-2010, 01:53 PM
Thanks. That's what I need.
small syntax correction
Max([col1])

Asi
11-03-2010, 02:05 PM
Sorry my mistake, I thought I saw something else...
No correction is needed

Imdabaum
11-03-2010, 03:16 PM
Sorry my mistake, I thought I saw something else...
No correction is needed

You probably did. I had made a mistake on the initial post of putting the [] outside the Max instead of inside them then just decided to take them out entirely as it will still work without them.

hansup
11-03-2010, 03:43 PM
Basically what I need is to run:
select max(col1) from T1 where col2=Me!ComBoBox1 and col3=Me!ComboBox2

get the returned value and set the text box with the returned value + 1. DMax() is another domain aggregate function which could work here.

=DMax("col1", "T1", "col2=" & Me!ComBoBox1 & " And col3=" & Me!ComboBox2) +1

Asi
11-04-2010, 04:57 AM
Yesterday I copied your code and saw that I need to change the position of the [], After that I saw it appears OK on your post. I told myself - "go to sleep you are not seeing very well..."

Thanks for your help.