Using VBA how to manipulate tables.

Insentive

Registered User.
Local time
Today, 04:32
Joined
Mar 12, 2008
Messages
13
Jus ta quick one. Can you tell me the functions to add records to table and such. Im not 100% how to use the recordset functions at the moment.
 
You can add a new record via a recordset by first grabbing the recordset into a recordset object, then useing the .AddNew and .Update functions of the recordset.

Below is an example (using an ADP rather than mdb, but it should be similar).

'First connect to the curren project and
Dim strSQL as string, rs as NEW ADODB.Recordset, cmd As New ADODB.Command

'Setup Command Object
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandTimeout = 60
cmd.CommandType = adCmdText
cmd.CommandText = "Select * from Table"

'Now get the recordset
rs.open cmd,, adOpenStatic, adLockOptimistic

'Now you can add the new record.
With rs
.AddNew
.ID = NewID
.FieldOne = NewData
.FieldTwo = NewData
.Update
End With

That's it! The new data should be in your table.
 

Users who are viewing this thread

Back
Top Bottom