Member Avatar for gowans07

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

Recommended Answers

All 4 Replies

you can use an SQL INSERT statement eg

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

Member Avatar for gowans07

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)"

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 & "#);"

Member Avatar for gowans07

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.