Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting a Record in table that has Auto_Increment

Status
Not open for further replies.

dbanker

Technical User
Sep 26, 2007
30
US
I need help

I'm trying to insert a row into a table using data from variables with values from an excel sheet. the problem I'm having is that the table I'm inserting them into has an Auto_increment field and I can't get the code right for it to work. Here is a sample of what I have:

Code
' ProjectNum is the Auto_increment field
INSERT INTO ProjectData ( ProjectNum, CompanyName, ProjectName, Latitude, Longitude, StateName, TotalPrints, TotalDiapos, FltLinesH, FltLinesM, FltLinesL, PhotoScaleH, GoDate, CreationDate, FlownDate, InvoiceDate )
VALUES (null, '" & GName & "', '" & ProjectName & "', '" & Lat & "', '" & Lon & "', '" & StateName & "', '" & NumPrints & "', '" & NumPos & "', '" & FltlinesH & "', '" & FltlinesM & "', 0, '" & PhotoScaleH & "', '', '" & Date & "', '', '');

When I run this I get Error Msg "You tried to assign the null value to a variable that is not a Variant data type"
If I change the null to a number I get Error Msg "Microsof set 1 field(s) to null due to a type convertion failure..." and doesn't append the record.

any help and or example code would be greatly appreciated. Thanks in advance
 
2 things:
1. Are you sure this is MYSQL and not Microsoft's SQL server. I say this because the errors you mention, are not something i have seen retruned by MYSQL.

and 2. Don't insert ProjectNum specifically. It should autogenerate it when you insert the row. you don't need to specify it as NULL.

so your query would look like:

Code:
INSERT INTO ProjectData (CompanyName, ProjectName, Latitude, Longitude, StateName, TotalPrints, TotalDiapos, FltLinesH, FltLinesM, FltLinesL, PhotoScaleH, GoDate, CreationDate, FlownDate, InvoiceDate )
VALUES ('" & GName & "', '" & ProjectName & "', '" & Lat & "', '" & Lon & "', '" & StateName & "', '" & NumPrints & "', '" & NumPos & "', '" & FltlinesH & "', '" & FltlinesM & "', 0, '" & PhotoScaleH & "', '', '" & Date & "', '', '');



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
You're right my mistake, I am using Sql server not MYSql thought I was in that Forum Sorry.
 
Its o.k. Still you should not need to specify the auto increment field in your insert statement.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top