Re: autonumber

From: Val Mazur (group51a_at_hotmail.com)
Date: 08/11/04


Date: Wed, 11 Aug 2004 00:15:32 -0400


Hi,

If you need to work with autonumbers, then check next links how to do this properly. There is no reason to create variables to increment this value and it is not reliable way. Best way is to declare field as an autonumber/identity and it should work

http://support.microsoft.com/default.aspx?scid=kb;en-us;221931&Product=ado

http://support.microsoft.com/default.aspx?scid=kb;EN-US;195910

http://support.microsoft.com/default.aspx?scid=kb;en-us;232144&Product=ado

http://support.microsoft.com/default.aspx?scid=kb;en-us;195224&Product=ado

-- 
Val Mazur
Microsoft MVP
  "Jeth" <jethph@hotmail.com> wrote in message news:uDLnATqfEHA.2896@TK2MSFTNGP11.phx.gbl...
  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 m
  ade:
  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