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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert data into Autonumber field

Status
Not open for further replies.

topone

Programmer
Jul 28, 2004
21
GB
Hello Everyone,
I am having a little bit of troubles storing data into a database. I will paste part of the code for simpler explanations.
I send data from a server to the host application and try to update it by using recordsets.
The first to tables work fine but when I try with the third one it crashes. Any ideas?
It is an Access Database, and the ID is an autonumber field, while the text field is a text field.
Any help welcome
Thanks
Paolo

Dim rs As ADODB.Recordset
Dim con As ADODB.Connection
Select case
Case 1
Case 2
.....

Case "DefPayTypes"
'Empty the table
''Status = "Preparing database to import data."
SQLStr = "DELETE * FROM DefPayTypes"
con.Execute SQLStr

''Status = "Importing data"
Do Until rs.EOF
'Insert the values into the table
SQLInsert = "INSERT INTO DefPayTypes (ID,Text)"
SQLInsert = SQLInsert & " VALUES("
SQLInsert = SQLInsert & rs!ID & ","
SQLInsert = SQLInsert & Chr(34) & rs!Text & Chr(34)
SQLInsert = SQLInsert & ")"
Debug.Print SQLInsert
con.Execute SQLInsert

rs.MoveNext
Loop
End Select
 
You're trying to paste data into an Autonumber field. Autonumber fields generate their own values. If you want to import an ID field, use a suitable numeric type which will usually be Integer

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top