I made a new table , the primary key field had been my HorseID , so I made
HorseID a number field and made my primary key something else so all my
functions in my database will still reconize HorseID, wont
they???....Thanks Bob
Dave,
This is probably the easiest way to accomplish your objective.
Open the properties window of the form and enter the following line of
text
into the "Default Value" of the HorseID property window.
=Nz(DMax("HorseID", "tblHorseInfo"), 0) + 1
There are other ways too. The important part is to load the Default
Value
of HorseID property window with whatever value you want. For example you
could on the Form_Open event, execute the following command.
Private Sub Form_Open(Cancel As Integer)
Me![HorseID].DefaultValue = Nz(DMax("HorseID", "tblHorseInfo"), 0) + 1
End Sub
Jack Cannon
:
Thanks Jack, so getting back to my original post where would I put this
code
for only my new record in increminate HorseID..............Thanks Bob
Bob,
You are correct that deleting records or aborting a data entry
operation
will cause gaps in the number. However, one needs to question whether
that
is actually a problem. If so, you can use a separate field other than
your
primary key for this function (as you indicated). This will eliminate
the
gaps caused by aborting a data entry operation but you will still get
gaps
if
you delete any records other than the very last one.
As far as the information showing up on a printed report, that should
not
be
the case unless you specifically design the report to do this.
Jack Cannon
:
Thanks Jack, So many people have told me that I should not use a
autonumber
field as a HorseID, As these numbers are actually used as printed IDs
on
a
report, so as if I dont save 10 entries by making mistakes or
deleting
the
number will jump from say 50 to 60
I created a new Table using HorseID as a numberfield and made ID my
Autonumber (New Values- Incremant)
Regards Bob
Bob,
From the information contained in your post, it would appear that
"HorseID"
should be an autonumber field (as well as a primary key) instead of
a
number
field. An autonumber field will increment automatically as I
interpret
your
objective.
Jack Cannon
:
This code opens my new record and I want it to add a sequential
number
to
"HorseID" (Number Field) but only if it is a new record
----------------------------------------
On Error GoTo Err_Command98_Click
DoCmd.OpenForm "frmHorseInfo", , , , acFormAdd
Exit_Command98_Click:
Exit Sub
Err_Command98_Click:
MsgBox Err.Description
Resume Exit_Command98_Click
-----------------------------------------------
Can I use this code somewhere:
--------------------------------------
Function NextHorseNo() As Long
NextHorseNo = Nz(DMax("HorseID", "tblHorseInfo"), 0) + 1
End Function
-- ----------------------------------------
Thanks in advance for any help with this......Bob
MS Access 2007 accdb
Windows XP Home Edition Ver 5.1 Service Pack 3