Storing a maximum value at runtime (1 Viewer)

choward

Registered User.
Local time
Yesterday, 18:53
Joined
Jan 31, 2008
Messages
39
Hi,

i am trying to do this in VBA:

DoCmd.RunSQL "UPDATE [Static Data] SET [Static Data].Result = max([Courses].[COURSE ID]) WHERE ((([Static Data].Criteria)='CMAX'))"

it basically stored in a table called STATIC DATA the highest Course ID value. It doesn't work and has this error:

"You tried to execute a query that does not include the specified expression 'Result'...."

Any help is appreciated!
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 02:53
Joined
Sep 12, 2006
Messages
15,743
have one query/expression to obtain the maximum, and store it in a variable

then use this variable in the update expression

so

DoCmd.RunSQL "UPDATE [Static Data] SET [Static Data].Result = "&myvariable

bear in mind that sql has syntax rules regarding datetime/text/numeric variable
 

mikebaldam

Registered User.
Local time
Today, 02:53
Joined
Oct 29, 2002
Messages
114
Dim iNum as Integer

'get highest number in table Courses, by Course ID
iNum =Nz(DMax("[COURSE ID]","[Courses]"),0)

DoCmd.RunSQL "UPDATE [Static Data] SET [Static Data].Result = " & iNum
 

Users who are viewing this thread

Top Bottom