Using variables with DMAX()

  • Thread starter Thread starter Phil Pereira
  • Start date Start date
P

Phil Pereira

I am trying to create a custom auto number field where I need to look up
the highest value of an item that belongs to a certain field, then add
1. If I use the literal
Text1.value=DMax("[ItemNumber]","Query1","[Client] = 'ClientName'") + 1

I get the desired results. But if I try to use a variable in place of
the [Client] = 'ClientName' part, all I get returned is #name? or some
unfathomable run time error, depending on how I try to concatenate the
combination of quotes, brackets, etc. Does anyone know how I can
reliably use variables in place of the literals with this? I can't find
any examples in the online help or searching the web.

thanks,

Phil
 
Phil Pereira said:
I am trying to create a custom auto number field where I need to look up
the highest value of an item that belongs to a certain field, then add
1. If I use the literal
Text1.value=DMax("[ItemNumber]","Query1","[Client] = 'ClientName'") + 1

I get the desired results. But if I try to use a variable in place of
the [Client] = 'ClientName' part, all I get returned is #name? or some
unfathomable run time error, depending on how I try to concatenate the
combination of quotes, brackets, etc. Does anyone know how I can
reliably use variables in place of the literals with this? I can't find
any examples in the online help or searching the web.

Text1.value=DMax("[ItemNumber]","Query1","[Client] = '" & VarName & "'") + 1
 
Hi Phil,
Yes.
Text1.value=DMax("[ItemNumber]","Query1","[Client] = '" & VaribleName & "'")
+ 1
note the double and singe quotes. it goes like this:
double quote[Client] = single quote, double quote & variableName & double
quote, single quote, double quote). If you copy this example and replace
VariableName with the actual variable name you should be ok.
HTH
 
Back
Top