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

Problem with subform data?

Status
Not open for further replies.

ffleitas

Technical User
Mar 15, 2001
85
US
Hello programmers,

I have a form that when it exits it runs this code:
Private Sub Form_Close()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Dim j As Integer
Dim stDocName As String

stDocName = "qryPickupSubPlusQnty"

Set db = CurrentDb
Set rs = db.OpenRecordset("tblPickupsSub", dbOpenDynaset)

If Me!frmPickupsOnCallSub![Quantity] > 1 Then

With rs
j = 1
For i = 1 To Me!frmPickupsOnCallSub![Quantity]
.AddNew
.Fields("PickupID") = Me![PickupID]
.Fields("ContainerID") = Me!frmPickupsOnCallSub![ContainerID]
.Fields("BarCode") = Me!frmPickupsOnCallSub![BarCode]
.Fields("ContainerName") = Me!frmPickupsOnCallSub![ContainerName]
.Fields("ContainerDescription") = Me!frmPickupsOnCallSub![ContainerDescription]
.Fields("Quantity") = 1
.Update
Select Case i
Case 4, 8, 12, 16: j = j + 1
End Select
Next i
End With

Set rs = Nothing
Set db = Nothing

Else

End If

DoCmd.OpenQuery stDocName
End Sub

The problem is that the data gets created for the last data row in the subform not all the information in the subform. How do I fix this?
 
Hi,

Where do you believe that you are 'stepping through' the records on the form? Which line of code should do this?

You are pointing to one form record all of the time and pointing to one DAO record all of the time - throughout all of the loops you have.

You have i and j variables that increment but do nothing when incremented.

You have one DAO record being continually changed by the same single form record.

What is your intention?

Regards,

Darrylle



"Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
Hi Darrylles,

How would you write the code above in order to process each line item on the subform rather than just one being the last one?

Thank you in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top