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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populating subform is not looping 1

Status
Not open for further replies.

splats

Technical User
Jan 2, 2003
131
Hello

I have a Main form (frmApplicantCostsCombo) that I would like to autopopulate a subform (sfrmPayment)based on fields from the Main Form. It is working except that it only puts out one record. I would like it to put in as many records as there are stated in the Disburse field (that says how many disbursements are given out).

As well, another problem that is happening is that the subform is not requerying after this event takes place. I would like to see the resulting new records in the subform as soon as the command button is pushed.

Any suggestions would be greatly appreciated. Below is my code for the Command button on the main form.

Thank you

Private Sub cmdDisbursement_Click()
On Error GoTo Err_cmdDisbursement_Click

Dim rst As DAO.Recordset
Dim i, DNumber As Integer
Dim Amount As Currency
Dim Appl As Integer


DNumber = Me.Disburse '- a control on the form
Amount = Me.AmtDisburse '- a control on the form
Appl = Me.ApplID
Set rst = CurrentDb.OpenRecordset("tblDisburse", dbOpenTable)
'Set rst = CurrentDb.OpenRecordset("Table1", dbOpenTable)

For i = 0 To i = DNumber - 1
rst.AddNew
rst!DisburseAmt = Amount
rst!ApplID = Appl
rst.Update
Next i

rst.Close

Set rst = Nothing

'Requery subform that new records are listing
sfrmPayment.Requery


Exit_cmdDisbursement_Click:
Exit Sub

Err_cmdDisbursement_Click:
MsgBox Err.Description
Resume Exit_cmdDisbursement_Click

End Sub
 
[tt]For i = 0 To i = DNumber - 1[/tt]?

Should it be: [tt]For i = 0 To DNumber - 1[/tt]

(GMT-07:00) Mountain Time (US & Canada)
 
Thank you CautionMP for your help. It partially works now, however, it does not show the results in the subform. Any ideas on how to get the subform to automatically show the results?
 
No clue, [tt]sfrmPayment.Requery[/tt] should do it.

CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top