Default value

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Default value

Post by Egg 'n' Bacon »

I'd like to have a field which has a defualt value of the Max of that field +1 (for various reasons, autonumber cannot be used), but just can't seem to get the syntax correct.

User avatar
HansV
Administrator
Posts: 78484
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Default value

Post by HansV »

This is not easy to implement in a table, for you aren't allowed to use functions such as DMax in the Default Value property of a field in a table.
But you can do it in a form bound to the table: set the Default Value of the text box bound to the field to

=DMax("name of the field","name of the table")+1

substituting the correct names, of course.
Best wishes,
Hans

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Re: Default value

Post by Egg 'n' Bacon »

Thank you Hans, that's exactly what I was after (sorry, should've said this was on a form).

Trouble is, all I'm getting is '#Name?'.
Here is what I've used;

Code: Select all

=DMax([ID],[tblEquip])+1
N.B. this is with 2007, 2003 format.

User avatar
HansV
Administrator
Posts: 78484
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Default value

Post by HansV »

The arguments to DMax should be strings:

=DMax("ID","tblEquip")+1
Best wishes,
Hans

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Re: Default value

Post by Egg 'n' Bacon »

Ah, so that's all that was wrong; quotes, not square brackets.

Thanks Hans