Counting on Demand (Dmax)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've read thru countless threads, but I can't seem to get my code to work.
My office handle hundreds of correspondence, only some of which get filed.
While I can easily use autonumber for each piece of paper that come thru, I
need a meaningful number for my file system that is sequential. I've tried
the following code, but it does not work. Can someone offer some advice?

My table is "Correspondence". The Form is "Correspondence Log." The cell
which stores the file numbers is "File#". I've called my toggle button
"Assign File#" which also stores a flag in a cell called "Filed"

If IsNull (File#) = True Then File# = Dmax("[File#]", "Correspondence") +1

I've tried this code in both before and after update. I've also tried it
using If File# = "0" which tends to pop up in the field despite the null
default.

Any suggestions?
 
Hello Pat.

:
[...]
If IsNull (File#) = True Then File# = Dmax("[File#]", "Correspondence") +1

I've tried this code in both before and after update. I've also tried it
using If File# = "0" which tends to pop up in the field despite the
null default.

Any suggestions?

How about:
If IsNull([File#]) Then [File#] = Dmax("[File#]", "Correspondence") +1
The # is the type specifier for "double". Your code is therefore looking for
a variable named File of type double.
To avoid this kind of error, make the variable declaration mandatory (Tools,
Options). This will insert "Option Explicit" in all new modules.
 
Wolfgang,

The sound you hear is me celebrating. Thank you very much. It works
perfectly.

Pat

Wolfgang Kais said:
Hello Pat.

:
[...]
If IsNull (File#) = True Then File# = Dmax("[File#]", "Correspondence") +1

I've tried this code in both before and after update. I've also tried it
using If File# = "0" which tends to pop up in the field despite the
null default.

Any suggestions?

How about:
If IsNull([File#]) Then [File#] = Dmax("[File#]", "Correspondence") +1
The # is the type specifier for "double". Your code is therefore looking for
a variable named File of type double.
To avoid this kind of error, make the variable declaration mandatory (Tools,
Options). This will insert "Option Explicit" in all new modules.
 
Back
Top