PC Review


Reply
Thread Tools Rate Thread

Getting the auto generated number.

 
 
Mark
Guest
Posts: n/a
 
      20th May 2010
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
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      20th May 2010
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 & "'")


--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"Mark" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSharpCodeProvider generated EXE embedded with ResourceWriter generated .resources fails... Jon Rista Microsoft C# .NET 4 1st Oct 2005 07:49 PM
W2K Error: "SVCHOST has generated errors...An error log is being generated" ? Al Dykes Windows XP General 1 14th May 2005 03:54 PM
The application, C:\WINDOWS\system32\lsass.exe, generated an application error The error occurred on 05/03/2004 @ 10:50:46.755 The exception generated was c0000005 at address 00900090 () =?Utf-8?B?cmljayBj?= Windows XP General 2 5th May 2004 03:36 AM
save.exe generated error - explorer.exe generated error JCGarcia Microsoft Windows 2000 1 31st Jan 2004 11:49 PM
Auto-generated code getting lost Heiko Milke Microsoft ASP .NET 3 19th Jan 2004 07:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:02 AM.