|
Thread: sql
-
Aug 11th, 2005, 03:00 AM
#1
Thread Starter
Member
sql
Hi,
I am doing an insert onto a table in access. I am inserting four fields while the fifth field which is an ID is auto generated. The sql statement is
VB Code:
sql = "INSERT INTO LogTable(Username,[Date],[Time],EditFields) VALUES('" & struser & "','" & Date & "','" & Time & "','New Mailbox " & newmailname & " created');"
Is there a way for me to store the value of the autogenerated id where this insert is being performed, since I need this id value later on.
Thanks
-
Aug 15th, 2005, 02:35 PM
#2
Re: sql
You will have to re-query in order to get the Autonumber because the autonumber is not created until the data has been inserted (or appended).
You should consider creating a function that will query the table to get the last ID number used and then increment it. THen you will know what the ID number is before you insert it. One additional item to note after you change the column from an auto number into a number field type make sure you change the index so that duplicat numbers are not allowed, so that a duplicate ID number is not entered.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 15th, 2005, 10:49 PM
#3
Re: sql
From the help file...
To find the last value that was used for an auto-increment column, you can use the following statement: SELECT @@IDENTITY. You cannot specify a table name. The value returned is from the last table, containing an auto-increment column, that was updated.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 16th, 2005, 05:38 AM
#4
Re: sql
 Originally Posted by rochak
I am doing an insert onto a table in access . . .
RobDog888,
Will @@IDENTITY work with an Access DB I thought it only worked with MS SQL, MySQL et. al.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 16th, 2005, 05:45 AM
#5
Thread Starter
Member
Re: sql
Can I use Dmax(field,table) since the last auto generated id would be the maximum?
-
Aug 16th, 2005, 05:52 AM
#6
Re: sql
 Originally Posted by rochak
Can I use Dmax(field,table) since the last auto generated id would be the maximum?
Yes you can.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 16th, 2005, 09:15 AM
#7
Re: sql
 Originally Posted by Mark Gambo
RobDog888,
Will @@IDENTITY work with an Access DB I thought it only worked with MS SQL, MySQL et. al.
Yes its available in Access but which version are you running? The quote is directly from the help file.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 16th, 2005, 10:40 AM
#8
Re: sql
 Originally Posted by RobDog888
Yes its available in Access but which version are you running? The quote is directly from the help file.
Weel they same you learn something new everyday. I wasn't aware of that, but I guess it is more of an ADO function rather that a DB specific function.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 16th, 2005, 11:56 AM
#9
Re: sql
I think its more of an DB function rather then a ADO function since it is more of a T-SQL92 standard SQL function if I'm not mistaken. So it depends more on the db supporting the SQL standards.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|