increment a column value automatically

how do i automatically increment a column's value in a form? that is if i add a new record, one of the columns should have it's value incremented by one. i dont want to use the autonumber field because of the problems it gives later on. i am sure there's an alternative code that can be incorporated in the form. i posted this here a few weeks back but got no where. so i am posting it agai.
thanks for all your help!
uk.

Comments

  • : how do i automatically increment a column's value in a form? that is if i add a new record, one of the columns should have it's value incremented by one. i dont want to use the autonumber field because of the problems it gives later on. i am sure there's an alternative code that can be incorporated in the form. i posted this here a few weeks back but got no where. so i am posting it agai.
    : thanks for all your help!
    : uk.
    :

    You can use VB code to do this.
    You make a query that gets the MAX() of the field you want to increment and use VB to open this Recordset.
    Then all you have to do is add one to it
    Example:
    Your query "MaxID" is like this:
    SELECT Max(ID) FROM YourTable
    [code]
    Function GiveID()
    Dim rst as Recordset
    Set rst = CurrentDB.OpenRecordset("MaxID")
    GiveID = rst.Fields(0) + 1
    rst.Close
    End Sub
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion