954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Adding Records back to database

Hi there, I've using the ADO connection within vb6. I know about the Data.Recordset.Addnew
and Data.Update way of adding a new record but is there a way of adding a new record without having to link objects to the Table/Entity? Is it possible to use variables to do this. Currently i have TxtBatch which i would like to assign to DBbatch and add the value of that record to the database. Database = MS Access 2000. Cheers

gowans07
Light Poster
48 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

you can use an SQL INSERT statement eg

"INSERT INTO mytable (newname, newamount) VALUES('Fred',25);"

ChrisPadgham
Posting Pro in Training
413 posts since Sep 2009
Reputation Points: 102
Solved Threads: 78
 

Quick response as always. Thanks. Below is the code i have created, when ran i get data type conversion error. I havent declared any of the variables, i have a feeling it could be because of DBBDate? Any ideas Up-Voted

DBOrderNumber = "3"
        DBCustomerID = "CODLAD"
        DBBDate = "01012011"
        Data6.Recordset.OpenRecordset "INSERT INTO Tbl_Order (Order_Number,Customer_ID,Date_Received).Value(DBOrderNumber,DBCustomerID,DBBDate)"
gowans07
Light Poster
48 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

if date_received column typed as a Date/Time, then I am not sure whether that is a valid format. There should be a space instead of a . before Value which should be VALUES, also you need to construct the string, you cannot pass in the variables because they are out of scope for the database engine.
the last part of the string, from the first ")" should be something like

) VALUES(" & OrderNumber & ", " & CustomerId & ", #" & DBBDate & "#);"

ChrisPadgham
Posting Pro in Training
413 posts since Sep 2009
Reputation Points: 102
Solved Threads: 78
 

Okay thank you very much, i think i have corrected the conversion error. I needed to declare what DBBDate was. Thanks again. Up-Voted

gowans07
Light Poster
48 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You