Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / December 2005

Tip: Looking for answers? Try searching our database.

GUID

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Branden Johnson - 12 Dec 2005 21:53 GMT
Using Microsoft Access 2002 (10.2627.2625)
Windows XP Pro SP1

I am writing a VB6 app to insert records into my Access database, based on
one of my forms. Upon clicking on the "Send" button in my app I have the
code generating a record in tblMRC and multiple records in tblPRODUCT. I
have a third table tblMRCPRODUCTLINK that I want to write a "link" record
for the MRC and the PRODUCT(s) that I am writing.

My problem is this: I do not have a good way of determining the PRODUCTID
(Primary Key) for the records I am writing. Here is an example of the INSERT
statement I am passing for a single PRODUCT INSERT:
sqlProduct = "" & _
           "INSERT INTO " & _
               "PRODUCT(NAME, DESCRIPTION, SERIALNUMBER, PARTNUMBER) " & _
           "VALUES " & _
               "(" & _
               txtName(0).Text & ", " & _
               txtDescription(0).Text & ", " & _
               txtSerialNum(0).Text & ", " & _
               txtProdNum(0).Text & _
               ")"

This statement inserts a record into the PRODUCT table and auto generates
the PRODUCTID (AutoNumber - Replication ID). Does anyone know if I can get
the next GUID, to be used by Access? This way I could specify the PRODUCTID
in my INSERT statement and problem solved.
Van T. Dinh - 13 Dec 2005 02:56 GMT
Before the INSERT execution: Not AFAIK.

Get the number allocated just after the Insert: Yes.

For single Record insertion and ID value is needed, I tend to create an
(empty) DAO.Recordset, use the AddNew Method to add the Record and then
retrieve the ID after Update Method.

Check Access VB Help on the AddNew / Update methods of DAO Recordset.

Signature

HTH
Van T. Dinh
MVP (Access)

> Using Microsoft Access 2002 (10.2627.2625)
> Windows XP Pro SP1
[quoted text clipped - 25 lines]
> PRODUCTID
> in my INSERT statement and problem solved.
David Lloyd - 13 Dec 2005 03:38 GMT
Branden:

Similar to Van's suggestion, is to use the SELECT @@Identity query to find
the ProductID value for the last inserted row.  The following KB article
gives more information on its usage.

http://support.microsoft.com/default.aspx?scid=kb;en-us;232144

Signature

David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.

Using Microsoft Access 2002 (10.2627.2625)
Windows XP Pro SP1

I am writing a VB6 app to insert records into my Access database, based on
one of my forms. Upon clicking on the "Send" button in my app I have the
code generating a record in tblMRC and multiple records in tblPRODUCT. I
have a third table tblMRCPRODUCTLINK that I want to write a "link" record
for the MRC and the PRODUCT(s) that I am writing.

My problem is this: I do not have a good way of determining the PRODUCTID
(Primary Key) for the records I am writing. Here is an example of the INSERT
statement I am passing for a single PRODUCT INSERT:
sqlProduct = "" & _
           "INSERT INTO " & _
               "PRODUCT(NAME, DESCRIPTION, SERIALNUMBER, PARTNUMBER) " & _
           "VALUES " & _
               "(" & _
               txtName(0).Text & ", " & _
               txtDescription(0).Text & ", " & _
               txtSerialNum(0).Text & ", " & _
               txtProdNum(0).Text & _
               ")"

This statement inserts a record into the PRODUCT table and auto generates
the PRODUCTID (AutoNumber - Replication ID). Does anyone know if I can get
the next GUID, to be used by Access? This way I could specify the PRODUCTID
in my INSERT statement and problem solved.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.