Capturing Max Value in Code

  • Thread starter Thread starter Al
  • Start date Start date
A

Al

Hi All,

I am trying to get the max value in a field of a table
using the following statement.

DoCmd.RunSQL "SELECT Max(ABC1MASTER![CLAIM7]) AS
MaxOfCLAIM7 FROM ABC1MASTER;"

The code produces the error:

A RunSQL action requires an argument consisting of an SQL
statement.

When run from the immediate window I get:

Compile error: Argument not optional

The only other argument is one for usetransaction, which
does not change the result.

Apparently the code does not recognize the SQL so I tried
parenthesis and separators but I am missing something

Once this is running, do I need to dimension MaxOfClaim7
to use the value since there is an option explicit line?

Thanks,

al
 
The only thing I can see that looks odd is the Bang here:
ABC1MASTER![CLAIM7])
it should be a dot
ABC1MASTER.[CLAIM7])
or leave the table name off completely
Max([CLAIM7]) AS MaxOfCLAIM7
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VBA query trouble 3
SQL -- VBA 3
Using Date fields in SQL 2
SQL statement doesn't work in VBA. 2
Running a SELECT statement 2
SQL Query in VBA 9
SQL - VBA once again 10
Open select query in vba code 4

Back
Top