Hi Guy's this should be an easy fix, i am trying to add records from one list to another, one list is on the left side of screen, the other is on the right calling my record sets rsL and rsR
rsL has got the data and trying to add to rsR
If the rsL has got 19 records, it is adding 19 records to rsR but only with the first record 19 times instead of 19 different records
I think i may not have looped correctly ? any adjustment would be appreciated
Code:
Dim rsL As DAO.Recordset, rsR As DAO.Recordset, myRecs As Integer, i As IntegerDim myItem As String, myStart As Date, myEnd As Date
myItem = "Fuel"
myStart = Format(Me.txtStartDate, "mm/dd/yyyy")
myEnd = Format(Me.txtEndDate, "mm/dd/yyyy")
Set rsL = CurrentDb.OpenRecordset("Select * From tblExpenses WHERE ItemRequired = '" & myItem & "' And Date Between #" & myStart & "# And #" & myEnd & "#")
If Not (rsL.BOF And rsL.EOF) Then
rsL.MoveFirst
Do Until rsL.EOF
myRecs = rsL.RecordCount
rsL.MoveNext
Loop
If MsgBox("Before You Continue To Update Your PPL List (Right List)," & vbNewLine & vbNewLine & _
"Confirm The Correct Amount Of Fuel Receipts From Your Fuel Listing (Left List)" & vbNewLine & vbNewLine & _
vbTab & "Start Date: " & Format(Me.txtStartDate, "ddd-dd-mmm-yyyy") & vbNewLine & _
vbTab & "End Date: " & Format(Me.txtEndDate, "ddd-dd-mmm-yyyy") & vbNewLine & vbNewLine & _
"There Should Be: " & myRecs & " Fuel Receipts" & vbNewLine & vbNewLine & _
"Continue To Update Now ?", vbQuestion + vbYesNo, "CONFIRM RECEIPTS") = vbNo Then
DoCmd.CancelEvent
Else
Set rsR = CurrentDb.OpenRecordset("Select * From tblFuelPrice")
With rsR
For i = 1 To myRecs
rsL.MoveFirst
.AddNew
!Date = rsL.Fields("Date")
!Vehicle = rsL.Fields("Vehicle")
!Price = rsL.Fields("TotalAmount")
!Time = rsL.Fields("FuelTime")
!Station = rsL.Fields("Supplier")
!Litres = rsL.Fields("Litres")
!PricePL = rsL.Fields("Litres") / rsL.Fields("TotalAmount")
.Update
rsL.MoveNext
Next i
End With
End If
End If
Me.frmFuelPrices.Requery
Set rsR = Nothing
Set rsL = Nothing