Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keyfield is number +1?

Status
Not open for further replies.

Heita

Instructor
Jun 21, 2001
6
0
0
SE
hi!

I have a primary key which is of a number type (long integer). When the form opens the text field containing the keyfield number should automatically be the latest saved number + 1.

I.e. Last tiped number 7879 and when the form opens it should be 7880 in the field.

Can the Default value be used in this? In what way then?

thanx
 
Use the autonumber datatype.

OR:

Stick the result of this into the field:
"SELECT MAX(keyfield)+1 from tblTable"
HF
 
Hi!

Thanx.

I can´t use Autonumber since the users kinda have started on 4578 and up so it dosen´t start at 1.

So I made an question instead, But when I dry to put it in the control source of the textfield or as default value it just says ?Name, as it cant find it or something. Do u have any sloution to that? (the question is the easiest way to make it count +1 on open).

Regards;
Heita
 
BEWARE!
If you calculate a field there is always the risk of getting the same result twice, wich would mess things up rather badly if it's a primary key. Imagine what would happen in a multi-user setting.
If you realy must calculate do it when saving the record.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.fldKey = 0 Or IsNull(Me.fldKey) Then
        Me.fldKey = DMax("fldKey", "tblTable") + 1
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top