Add a record in the background

  • Thread starter Thread starter Keith
  • Start date Start date
K

Keith

I have a main data entry screen with one subform on it.
The main for contains information about a customer, and
the sub form contains information about orders. One entry
per ordered item.

I have put in a routine to check once a new entry has been
entered in the subform, whether there is already a
standard delivery item added for this order.

What I want the system to do is after the recrd has been
saved, if there is no delivery item append a delivery
entry to the table.

I was going to do this with access basic, but I have been
away from programming for about 5 years, and I can't
remember the process.

Can anybody help? I need to add the record, then take the
current customers reference and the date of the order and
update the new record with this information.
 
Keith said:
I have a main data entry screen with one subform on it.
The main for contains information about a customer, and
the sub form contains information about orders. One entry
per ordered item.

I have put in a routine to check once a new entry has been
entered in the subform, whether there is already a
standard delivery item added for this order.

What I want the system to do is after the recrd has been
saved, if there is no delivery item append a delivery
entry to the table.

I was going to do this with access basic, but I have been
away from programming for about 5 years, and I can't
remember the process.

Can anybody help? I need to add the record, then take the
current customers reference and the date of the order and
update the new record with this information.

Create this function and place it in a module or the form you are using :


Public Function AddNewRecordToCustomerOrderTable(TheCustomerNumber As Long,
TheDate As Date)

Dim dbs As ADODB.Connection, rstSource As ADODB.Recordset
Set dbs = CurrentProject.Connection ' connect to the database
Set rst= New Recordset ' declare a recordset

rst.Open "CustomerOrderDetailTableName", dbs, adOpenDynamic,
adLockOptimistic ' open the table
rst.AddNew ' this adds a new record in the table
rst!CustomerNumber= TheCustomerNumber
rst!OrderDate = TheDate
rst.Update
rst.Close ' close the table
Set rst= Nothing
dbs.Close ' close the database
Set dbs = Nothing

End Function
 
Back
Top