wlwebb
asked on
Access - Loop not creating expected number of new recs in a CurrentDb.Execute INSERT INTO
Hello All,
I am having trouble with a CurrentDb.Execute INSERT INTO that isn't creating the correct number of new records.
This is a tabbed form with multiple tabs each having a subform.
On the first tab I have an Unbound textbox to count the number of records in a query. That textbox is named [txtCntActiveCurrencyDenom inations]
The Control Source for that box is =DCount("[qry_Denomination _Currency_ Active]![D enominatio nID]","[qr y_Denomina tion_Curre ncy_Active ]","[qry_D enominatio n_Currency _Active]![ Denominati onID]")
The SQL of that query which is counts is
Now then what I am expecting to happen in this case is that it will insert new records with a DenomintionID of 2, 3, 4, 5, 6 & 7
However, it is Inserting 2, 3, 4, 5 & 6 (NOT 7)
The code that Executes all of this is
I am having trouble with a CurrentDb.Execute INSERT INTO that isn't creating the correct number of new records.
This is a tabbed form with multiple tabs each having a subform.
On the first tab I have an Unbound textbox to count the number of records in a query. That textbox is named [txtCntActiveCurrencyDenom
The Control Source for that box is =DCount("[qry_Denomination
The SQL of that query which is counts is
SELECT Denomination.DenominationID, Denomination.Denomination, Denomination.DenominationMultiple, Denomination.DenominationTypeID, Denomination.Active, DCount("DenominationID","qry_Denomination_Currency_Active","DenominationID <= " & [DenominationID]) AS CurrencyActiveDenominationSeq
FROM Denomination
WHERE (((Denomination.DenominationTypeID)=2) AND ((Denomination.Active)=-1));
Now then what I am expecting to happen in this case is that it will insert new records with a DenomintionID of 2, 3, 4, 5, 6 & 7
However, it is Inserting 2, 3, 4, 5 & 6 (NOT 7)
The code that Executes all of this is
Private Sub GenerateLVLMachineLines2(IsMachinePull As Boolean)
Dim bytCounter As Byte, lngMyRptgSeqID As Long, lngMyShiftRptgLVLCtlID As Long, i As Integer, z As Integer
Dim strSQL As String
lngMyRptgSeqID = GetMyShiftSeqID()
lngMyShiftRptgLVLCtlID = GetMyShiftRptgLVLCtlID()
i = 1 ' This counter is for Inserting Active Currency Seq to Machine Pull tbl
z = DMax("ShiftRptgMachPullCountCtlID", "ShiftReportingMachinePullCountCtl", "ShiftRptgMachPullCountCtlID")
Do Until bytCounter = Me.txtNbrMachines
CurrentDb.Execute "INSERT INTO ShiftReportingLVL (ShiftRptgLVLCtlID, LVLPositionNbr, RptgSeqID, MachinePulled) VALUES (" & lngMyShiftRptgLVLCtlID & "," & bytCounter + 1 & "," & lngMyRptgSeqID & "," & True & ")", dbFailOnError
bytCounter = bytCounter + 1
Loop
Do Until i = Forms![frm_DataReporting]![LVLReportingTypeSelect]![txtCntActiveCurrencyDenominations]
strSQL = "INSERT INTO ShiftReportingMachinePullDetails (ShiftRptgMachPullCountCtlID, DenominationID) SELECT " & z & ", DenominationID FROM [qry_Denomination_Currency_Active] WHERE [CurrencyActiveDenominationSeq]= " & i
CurrentDb.Execute strSQL, dbFailOnError
i = i + 1
Loop
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In addition, change these for clarity:
line 6
z = DMax("ShiftRptgMachPullCou ntCtlID", "ShiftReportingMachinePull CountCtl")
textbox controlsource
=DCount("*","[qry_Denomina tion_Curre ncy_Active ]")
line 6
z = DMax("ShiftRptgMachPullCou
textbox controlsource
=DCount("*","[qry_Denomina
ASKER
Irog......I think you meant line 9 but,
Didn't understand that last comment.......
Do I add textbox controlsource as a new line of code???? or am I replacing line 9
Didn't understand that last comment.......
Do I add textbox controlsource as a new line of code???? or am I replacing line 9
You're right, I meant replace line 9. The 2nd code I gave you was a shortened version of what you have in your textbox named txtCntActiveCurrencyDenomi nations.
ASKER
Ok... I understand........Thanks
ASKER
Thank you as always!!! And thank you for the additional comment!
ASKER