Do you have a control named "SENE CASE #" on your form? or is that field in
the form's RecordSource query? Assuming that it is a control, and that that
is why you're using SENE_CASE__ as it's "equivalent" in the code, let's try
this:
Private Sub Form_Current()
If Me.NewRecord = True And _
Len(Me.[SENE CASE #].Value & "") = 0 Then _
Me.[SENE CASE #].Value = _
Nz(DMax("SENE CASE #", "SENE Sar Log"), 0) + 1
End Sub
I have slightly changed the code to test if the "SENE CASE #" control
already has a value (using the Len function), and to not change its value if
it already has one.
The actual field name is SENE CASE #, so that is the name you must use in
the DMax function. The SENE_CASE__ is VBA's "equivalent" for the field name
because you cannot have a field or object or control name in VBA with spaces
or with # characters unless you enclose the name in [ ] characters. The
"alternative" code example that uses this VBA "equivalent" would be this:
Private Sub Form_Current()
If Me.NewRecord = True And _
Len(Me.SENE_CASE__.Value & "") = 0 Then _
Me.SENE_CASE__.Value = _
Nz(DMax("SENE CASE #", "SENE Sar Log"), 0) + 1
End Sub
In fact, may I recommend that you not use spaces or # character (or any of a
large number of special characters) in field or control or table names? See
these articles for more information:
List of reserved words in Access 2002 and Access 2003
http://support.microsoft.com/default.aspx?scid=kb;en-us;286335
List of Microsoft Jet 4.0 reserved words
http://support.microsoft.com/?id=321266
Special characters that you must avoid when you work with Access databases
http://support.microsoft.com/?id=826763
--
Ken Snell
<MS ACCESS MVP>
Scuda said:
Thanks Ken, I am using:
Private Sub Form_Current()
If Me.NewRecord = True Then Me.SENE_CASE__.Value = _
Nz(DMax("SENE_CASE__", "SENE Sar Log"), 0) + 1
End Sub
Where my field I want to add a number to is: "SENE CASE #" ( text box) and
the table name is SENE Sar Log.
Thanks again