Consulting

Results 1 to 7 of 7

Thread: Getting a result of a query

  1. #1
    VBAX Regular
    Joined
    Feb 2009
    Posts
    35
    Location

    Getting a result of a query

    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

  2. #2
    VBAX Expert Imdabaum's Avatar
    Joined
    Jun 2006
    Posts
    652
    Location
    Have you tried...

    [vba]
    =DLookup("Max(col1)", "[T1]", "[Col2] = " & Me!ComboBox2) +1
    [/vba]
    Someday I'll understand everything...
    Even then...I'll still pretend I'm a beginner.

  3. #3
    VBAX Regular
    Joined
    Feb 2009
    Posts
    35
    Location
    Thanks. That's what I need.
    small syntax correction
    Max([col1])

  4. #4
    VBAX Regular
    Joined
    Feb 2009
    Posts
    35
    Location
    Sorry my mistake, I thought I saw something else...
    No correction is needed

  5. #5
    VBAX Expert Imdabaum's Avatar
    Joined
    Jun 2006
    Posts
    652
    Location
    Quote Originally Posted by Asi
    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.
    Someday I'll understand everything...
    Even then...I'll still pretend I'm a beginner.

  6. #6
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    447
    Location
    Quote Originally Posted by Asi
    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.

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

  7. #7
    VBAX Regular
    Joined
    Feb 2009
    Posts
    35
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •