I wonder if anyone can help.
I need to add a new record in table by taking that last number from the previous record and adding 1. I don't like using the autonumber that Access uses.
In Access 97 I would use this and it works fine
Dim dbs As Database
Dim rst As Recordset
Dim temp As Integer
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("01-TBL-INVENTORY", dbOpenDynaset)
Do Until rst.EOF
rst.MoveNext
Loop
rst.MovePrevious
temp = rst![tag_id]
rst.AddNew
rst![tag_id] = "00" & (temp + 1)
rst.Update
If I convert the code to Access 2003 it works as well, but if I rewrite the code in 2003 it does not work. I thought that this was the answer, but it comes up wuith an error "dbs As Database" - user-defined type not defined.
Dim dbs As DAO.database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("01-TBL-INVENTORY",dbOpenDynaset)
Do Until rst.EOF
rst.MoveNext
Loop
rst.MovePrevious
temp = rst![tag_id]
rst.AddNew
rst![tag_id] = "00" & (temp + 1)
rst.Update
I need to add a new record in table by taking that last number from the previous record and adding 1. I don't like using the autonumber that Access uses.
In Access 97 I would use this and it works fine
Dim dbs As Database
Dim rst As Recordset
Dim temp As Integer
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("01-TBL-INVENTORY", dbOpenDynaset)
Do Until rst.EOF
rst.MoveNext
Loop
rst.MovePrevious
temp = rst![tag_id]
rst.AddNew
rst![tag_id] = "00" & (temp + 1)
rst.Update
If I convert the code to Access 2003 it works as well, but if I rewrite the code in 2003 it does not work. I thought that this was the answer, but it comes up wuith an error "dbs As Database" - user-defined type not defined.
Dim dbs As DAO.database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("01-TBL-INVENTORY",dbOpenDynaset)
Do Until rst.EOF
rst.MoveNext
Loop
rst.MovePrevious
temp = rst![tag_id]
rst.AddNew
rst![tag_id] = "00" & (temp + 1)
rst.Update