Appending a record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In the AfterUpdate event of the first of two subforms, linked to a main form,
I would likd to put in code that appends a record to the table in the 2nd
subform. Then requery, if necessary, the 2nd subform so the new record will
show. How can I do this from one subform to another?

Thanks,

Dennis
 
Simplest way would be to AddNew to the RecordsetClone of the other subform,
as this avoids the need to Requery.

This kind of thing:

Dim rs As DAO.RecordsetClone
Set rs = Me.Parent![NameOfYourOtherSubformControl].Form.RecordsetClone
rs.AddNew
rs![SomeField] = 99
rs![AnotherField] = "some text"
'etc for other fields.
rs.Update
Set rs = Nothing
 
Allen,

I am unsure about an error that I am getting with the following code:

Private Sub ProductID_AfterUpdate()
Dim rs As DAO.RecordsetClone
Set rs = Me.Parent![ShippedRental].Form.RecordsetClone
rs.AddNew
rs![ProductID] = [ProductID]
rs![TransactionDate] = [TransactionDate]
'etc for other fields.
rs.Update
Set rs = Nothing

End Sub

The error is "Compile error: User-defined type not defined." with the
following part of the code highlighted: rs As DAO.RecordsetClone

RecordsetClone is part of Access Form in my Object Browser.
In my References I am using DAO 3.6 Object Library and I am using Access 2000.
1)Am I not declaring something?
2) Also please check the following lines to see if I am on the right track.

rs![ProductID] = [ProductID] (Both subforms have a ProductID)
rs![TransactionDate] = [TransactionDate] (Both subforms have a
TransactionDate)

Thanks,

Dennis

Allen Browne said:
Simplest way would be to AddNew to the RecordsetClone of the other subform,
as this avoids the need to Requery.

This kind of thing:

Dim rs As DAO.RecordsetClone
Set rs = Me.Parent![NameOfYourOtherSubformControl].Form.RecordsetClone
rs.AddNew
rs![SomeField] = 99
rs![AnotherField] = "some text"
'etc for other fields.
rs.Update
Set rs = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Don said:
In the AfterUpdate event of the first of two subforms, linked to a main
form,
I would likd to put in code that appends a record to the table in the 2nd
subform. Then requery, if necessary, the 2nd subform so the new record
will
show. How can I do this from one subform to another?
 
The error message indicates that you do not have a reference to the DAO
library.

Open the code window.
Choose References on the Tools menu.
Check the box beside DAO 3.6

More info on references:
http://allenbrowne.com/ser-38.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Don said:
Allen,

I am unsure about an error that I am getting with the following code:

Private Sub ProductID_AfterUpdate()
Dim rs As DAO.RecordsetClone
Set rs = Me.Parent![ShippedRental].Form.RecordsetClone
rs.AddNew
rs![ProductID] = [ProductID]
rs![TransactionDate] = [TransactionDate]
'etc for other fields.
rs.Update
Set rs = Nothing

End Sub

The error is "Compile error: User-defined type not defined." with the
following part of the code highlighted: rs As DAO.RecordsetClone

RecordsetClone is part of Access Form in my Object Browser.
In my References I am using DAO 3.6 Object Library and I am using Access
2000.
1)Am I not declaring something?
2) Also please check the following lines to see if I am on the right
track.

rs![ProductID] = [ProductID] (Both subforms have a ProductID)
rs![TransactionDate] = [TransactionDate] (Both subforms have a
TransactionDate)

Thanks,

Dennis

Allen Browne said:
Simplest way would be to AddNew to the RecordsetClone of the other
subform,
as this avoids the need to Requery.

This kind of thing:

Dim rs As DAO.RecordsetClone
Set rs =
Me.Parent![NameOfYourOtherSubformControl].Form.RecordsetClone
rs.AddNew
rs![SomeField] = 99
rs![AnotherField] = "some text"
'etc for other fields.
rs.Update
Set rs = Nothing

Don said:
In the AfterUpdate event of the first of two subforms, linked to a main
form,
I would likd to put in code that appends a record to the table in the
2nd
subform. Then requery, if necessary, the 2nd subform so the new record
will
show. How can I do this from one subform to another?
 
Back
Top