Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_cdo thread: Insert AutoNumber(in MSAccess)


Message #1 by "Savonnya D. Rodrigues" <srod@f...> on Mon, 19 Mar 2001 15:14:41 -0800
Is there a way to insert an autonumber that has been generated by one. 

Can you insert that value into another table? Evertime, I try to insert 

I get an error saying a (missing operator) in query expression. Can 

someone help me with this?



Message #2 by Scott Watermasysk <swatermasysk@C...> on Mon, 19 Mar 2001 16:48:02 -0500
If I understand you correctly, you want to add a record to a table, and then

find the autonumber of the row you just inserted, and use that number

somewhere else?



After you open your record set:

rs.AddNew

rs("ABC") = x

rs("DEF") = y

...etc etc..

'Update the Record Set

rs.Update



'Now you can read the AutoNumber Field

AutoNum = rs("AutoUpdate")

rs.Close



You can now take this number (AutoNum) and insert it into another table.



-Scott



P.S. If you want to insert this number into another "AutoNumber" field, then

it will not work. You can not insert anything into an autonumber field.



If you are also going to be inserting your own "AutoNumbers" you can simply

change the field to a number field.



-----Original Message-----

From: Savonnya D. Rodrigues [mailto:srod@f...]

Sent: Monday, March 19, 2001 6:15 PM

To: ASP CDO

Subject: [asp_cdo] Insert AutoNumber(in MSAccess)





Is there a way to insert an autonumber that has been generated by one. 

Can you insert that value into another table? Evertime, I try to insert 

I get an error saying a (missing operator) in query expression. Can 

someone help me with this?





---

SoftArtisans helps developers build robust, scalable Web applications!

Excel Web reports, charts: http://www.softartisans.com/excelwriter.html

File uploads: http://www.softartisans.com/saf.html

Transactional file management: http://www.softartisans.com/saf1.html

Scalability: http://www.softartisans.com/saxsession.html

ASPstudio value pack: http://www.softartisans.com/aspstudiosuite.html



swatermasysk@C...


Message #3 by Lauralyn.Ninow@c... on Mon, 19 Mar 2001 15:38:26 -0600
This message is in MIME format. Since your mail reader does not understand

this format, some or all of this message may not be legible.



------_=_NextPart_001_01C0B0BC.EE815F10

Content-Type: text/plain;

	charset="iso-8859-1"



When you insert a record in access, it fills in the value for you. You won't

be able to put your own number in the autonumber field.  If you want to put

that same number in table2, you will need to save the new record (in

table1), then requery table1 for the record you just inserted to get the new

value from the autonumber field, save it as a temp variable to use when

inserting it in table2.



As far as your error goes, we need to see what your SQL statement is in

order to help you.  It is a syntax error,... we need the syntax.



What does this have to do with CDO?



Lauralyn



> -----Original Message-----

> From: Savonnya D. Rodrigues [mailto:srod@f...]

> Sent: Monday, March 19, 2001 5:15 PM

> To: ASP CDO

> Subject: [asp_cdo] Insert AutoNumber(in MSAccess)

> 

> 

> Is there a way to insert an autonumber that has been 

> generated by one. 

> Can you insert that value into another table? Evertime, I try 

> to insert 

> I get an error saying a (missing operator) in query expression. Can 

> someone help me with this?

> 

> 

> ---

> SoftArtisans helps developers build robust, scalable Web applications!

> Excel Web reports, charts: 

> http://www.softartisans.com/excelwriter.html

> File uploads: http://www.softartisans.com/saf.html

> Transactional file management: http://www.softartisans.com/saf1.html

> Scalability: http://www.softartisans.com/saxsession.html

> ASPstudio value pack: http://www.softartisans.com/aspstudiosuite.html




> $subst('Email.Unsub')

> 




Message #4 by "Savonnya D. Rodrigues" <srod@f...> on Thu, 22 Mar 2001 08:41:29 -0800
The code is below. The auto number is in the Software table and I want the

same number that is in the Software table to be also inserted into the

Installation table. The field in the software table with the autonumber is

softwareID(Software table) and the field that I want the autonumber inserted

into is called softwareID(Installation table), and it is not an autonumber I

just want to insert the autonumber. Please can you help me with this.



'Build the insert string



strSQL1 = "Insert into Software (SerialNum, LicenseKeyNum, ProductID, " &

"ServerApplication, Manufacture, ProductName, Version, Description, Status,

EquipmentType, Location, Comment) " & "Values('" &

Request.Form("txtSerialNum") & "','" & Request.Form("txtLicenseKeyNum") &

"','" & Request.Form("txtProductID") & "','" &

Request.Form("txtServerApplication") & "','" &

Request.Form("txtManufacture") & "','" & Request.Form("txtProductName") &

"','" & Request.Form("txtVersion") & "','" & Request.Form("txtDescription")

& "','" & Request.Form("txtStatus") & "','" &

Request.Form("txtEquipmentType") & "','" & Request.Form("txtLocation") &

"','" & Request.Form("txtComment") & "')"



strSQL2 = "Insert into PurchaseOrder (SerialNum,POComment,PCQuote , " &

"DateReceived, DateApproved,Cost, MaintenanceAgree, LicenseLocation) " &

"Values('" & Request.Form("txtSerialNum") & "','" &

Request.Form("txtPOComment") & "','" & Request.Form("txtPCQuote") & "','" &

Request.Form("txtDateReceived") & "','" & Request.Form("txtDateApproved") &

"','" & Request.Form("txtCost") & "','" &

Request.Form("txtMaintenanceAgree") & "','" &

Request.Form("txtLicenseLocation") & "')"



strSQL3 = "Insert into Installation (SoftwareID, SerialNum, UserName , " &

"EmpNum, InstalledBy, InstalledDate) " & "Values('" &

Request.Form("txtSoftwareID") & "'" & Request.Form("txtSerialNum") & "','" &

Request.Form("txtUserName") & "','" & Request.Form("txtEmpNum") & "','" &

Request.Form("txtInstalledBy") & "','" & Request.Form("txtInstalledDate") &

"')"



'Create and open the database object



Set objConn = Server.CreateObject("ADODB.Connection")



objConn.Open "DSN=ESS2"



'Create the command object



Set objCmd = Server.CreateObject("ADODB.Command")



'Set the command object properties



Set objCmd.ActiveConnection = objConn



objCmd.CommandText = strSQL1



objCmd.CommandType = adCmdText



objCmd.Execute



'Execute the command



objCmd.CommandText = strSQL2



objCmd.CommandType = adCmdText



objCmd.Execute



'Execute the command



objCmd.CommandText = strSQL3



objCmd.CommandType = adCmdText



objCmd.Execute











----- Original Message -----

From: "Scott Watermasysk" <swatermasysk@C...>

To: "ASP CDO" <asp_cdo@p...>

Sent: Monday, March 19, 2001 1:48 PM

Subject: [asp_cdo] RE: Insert AutoNumber(in MSAccess)





> If I understand you correctly, you want to add a record to a table, and

then

> find the autonumber of the row you just inserted, and use that number

> somewhere else?

>

> After you open your record set:

> rs.AddNew

> rs("ABC") = x

> rs("DEF") = y

> ...etc etc..

> 'Update the Record Set

> rs.Update

>

> 'Now you can read the AutoNumber Field

> AutoNum = rs("AutoUpdate")

> rs.Close

>

> You can now take this number (AutoNum) and insert it into another table.

>

> -Scott

>

> P.S. If you want to insert this number into another "AutoNumber" field,

then

> it will not work. You can not insert anything into an autonumber field.

>

> If you are also going to be inserting your own "AutoNumbers" you can

simply

> change the field to a number field.

>

> -----Original Message-----

> From: Savonnya D. Rodrigues [mailto:srod@f...]

> Sent: Monday, March 19, 2001 6:15 PM

> To: ASP CDO

> Subject: [asp_cdo] Insert AutoNumber(in MSAccess)

>

>

> Is there a way to insert an autonumber that has been generated by one. 

> Can you insert that value into another table? Evertime, I try to insert 

> I get an error saying a (missing operator) in query expression. Can 

> someone help me with this?

>

>

  Return to Index