Getting the auto generated number.

M

Mark

Hi All,

I'm inserting a record into a table and have one field using the auto
number. I need to get this number so I can email it. I'm using the code
below to do this and it works fine. I just wanted to see if there is a
better way of doing this.
Thanks for the input!

vSQL = "SELECT audit_history.audit_id " & _
"FROM audit_history " & _
"where Associate_id = '" & [txAssociate_id] & "'"

Set rs = db.OpenRecordset(vSQL)
rs.MoveLast

vSQL = rs!audit_id
 
D

Douglas J. Steele

What you're using really isn't a good idea in the first place! Using
MoveLast only makes sense if you know the order in which the records are
retrieved, and since you don't have an Order By clause in your SQL
statement, you don't know that.

Try just using

vSQL = DMax("audit_id ", "audit_history ", _
"[Associate_id] = '" & Me.txAssociate_id & "'")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

join 2 tables with different links of data 2
importing fields from 1 DB to another DB 1
Duplicate Numbers 6
Auto generatered number 1
Do loop 1
Type Mismatch Problem 3
Auto Number Lookup 1
Auto Fill info 2

Top