Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting a record into a subform

Status
Not open for further replies.

nhtraven

Technical User
Dec 10, 2000
114
US
Hi all.

I have a question, i want to insert a new record in a subform and insert the previous balance from the record before it. I have the following function where i add the new record

Function AddBalance(rstTemp As DAO.Recordset, Bal As Double)
'Adds a new record to the recordset using the balance for previous balance

With rstTemp
.AddNew
!BeginBalance = Bal
.Update
'.Bookmark =
End With
End Function

When i run it i get the following error:
Runtime Error: 3201
"You cannot add or change record because related record is required in table"tblCustomers"

I am not sure how to go about adding it to the Mainform table. Any help would be appreciated.

THanks
RAven
 
Hi there,

The record on the subform must have a record key link to the primary key on the main form. If there is no link you get that message. You can not add a record on the subform without a record link being present with the main form.
 
ok, i figured that one out, but when it adds the record it places the new record above the one it received the previous balance. Any ideas as to how to make it go to end of all records in view?

Thanks
Raven
 
Curious question: Have you set the subform to view "continuous forms"? I have run into this problem before. Changing this property will show all of the records.

crpjaviman
 

crp,

Actually i figured it out, i did not have the code in correct order or the enough of it. Here is what i did, if any inquiring minds want to know = )

Function AddBalance(rstTemp As DAO.Recordset, Bal As Double, CID As Long)
'Adds a new record to the recordset using the balance for previous balance

Dim varBookmark As Variant


rstTemp.MoveLast
varBookmark = rstTemp.Bookmark




With rstTemp
.AddNew
!ClientID = CID
!BeginBalance = Bal
.Update
.Bookmark = varBookmark

End With

End Function



And if i told you how many gray hairs that gave me, whew < 3 lines of code>
I am hoping that the aged receivables report that goes in this database goes alot EASIER = )

Raven
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top