autonumber

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jeth (jethph_at_hotmail.com)
Date: 08/08/04


Date: Sun, 8 Aug 2004 11:22:45 +0700


Im having a problem in ado. I've made a function that will autonumber the records. When you press the add button button the itemno field will automatically increment. Here is the function I've made:

Function autoadd()
Dim add As Integer
Dim toadd As String
aditems.Recordset.MoveLast
*itemnum = aditems.Recordset!itemno.Value
add = Val(itemnum) + 1
toadd = Str(add)
autoadd = toadd

*The itemnum is declared as string at form level.

And here is the code in the add button:
Private Sub cmdadd_Click()
Dim added
txtitemno.Locked = False
lblitemno.Caption = ""
added = autoadd
aditems.Recordset.addnew
txtitemno.Text = added
*Call txtenbl
txtitemname.SetFocus
*Call savecancelenable
txtitemname.Locked = True
End Sub

*The txtenbl function will make the textboxes locked property to false and function savecancelenable will make the save & cancel button enabled.

I'm getting a binding collection error and should i make a decrement code anytime I delete a record or can you suggest a simpler code.
Hoping for your suggestion. Thanks!!!

Jethro




tech.gif
Quantcast