View Full Version : Update records


AndyShuter
01-15-2005, 02:33 PM
Erm, I know this sound a bit silly....but I woudered if there was a way of adding anew record to a table using vb code?

My table is called tblTransmissions

The fields are
TransmissionCode, AutoNumber
TransmissionDate, Date/Time
TransmissionTime, Date/Time
TransmissionStatus / Text
TransactionCode / Number (Linked to another table by One-To-Many)

When I hit a command button, I would like to update the recordset by firstly adding a new record. Then set Date & Time to Now, Then TransmissionStatus to a control on a form, same with the Transaction Code.

Normally I would place the values on a form and update the values that way, but just wondered if this was possible!

Thanks

pbaldy
01-15-2005, 11:23 PM
Of course. You can either execute an append query in code (CurrentDb.Execute) or open a DAO or ADO recordset and add the record that way.

Pat Hartman
01-16-2005, 07:53 PM
Date and time should be in the same field. It will be easier to work with. Look up AddNew to see code examples for DAO and ADO.

shadow9449
01-16-2005, 08:12 PM
Pbaldy:

Why do people recommend using DAO/ADO for appending data rather than DoCmd.RunSQL "INSERT INTO...."?

I understand the use of DAO/ADO for cycling through records, but I'm not sure why it's better than using an SQL command.

Thanks.

SHADOW

pbaldy
01-16-2005, 08:32 PM
Shadow: I don't know why. I simply included it as one of the alternatives. Executing SQL should be more efficient. By the way, CurrentDb.Execute is more efficient that DoCmd.RunSQL.

shadow9449
01-16-2005, 08:37 PM
Paul:

Executing SQL should be more efficient. By the way, CurrentDb.Execute is more efficient that DoCmd.RunSQL.

I didn't know that CurrentDb.Execute can run a SQL statement. I've always used DoCmd.RunSQL. If you say that it's more efficient, then I'll change my ways :)

Thanks

SHADOW