PC User
Registered User.
- Local time
- Today, 13:14
- Joined
- Jul 28, 2002
- Messages
- 193
I'm having trouble with my loop indexing. I can't seem to get the counter "j" to number the array correctly. The numbering should be sequential. Can someone help?
Thanks,
PC
Code:
Public Function InsertLabels()
Dim intCount As Integer
Dim intRecCount1 As Integer, intRecCount2 As Integer
Dim intChemicalID As Integer, intComponentID As Integer
Dim strComponentName As String
Dim i As Integer, j As Integer
Set Db = CurrentDb()
Set rst1 = Db.OpenRecordset("tabUNIDOCSfields", dbOpenDynaset) 'Source/Target
rst1.MoveLast
rst1.MoveFirst
intRecCount1 = rst1.RecordCount
j = 0
rst1.MoveFirst
Do Until rst1.EOF
intChemicalID = rst1!ChemicalID
strSelect = "SELECT [tabUNIDOCSfields].* "
strFrom = "FROM [tabUNIDOCSfields] "
strWhere = "WHERE tabUNIDOCSfields.ChemicalID = " & intChemicalID
strSQL = strSelect & strFrom & strWhere
Debug.Print "ChemicalID = " & intChemicalID
Set rst2 = Db.OpenRecordset(strSQL) 'Subsource
rst2.MoveLast
rst2.MoveFirst
intRecCount2 = rst2.RecordCount
intCount = DCount("HazardousComponentID", "tabUNIDOCSfields", "ChemicalID = " & intChemicalID)
intChemicalID = rst1!ChemicalID
Debug.Print "Number of Components = " & intCount
Debug.Print "Records of Components = " & intRecCount2
Do Until rst2.EOF
intComponentID = rst1!HazardousComponentID
strComponentName = rst1!COMPONENT_NAME
Debug.Print "ComponentID = " & intComponentID & " " & strComponentName
j = j + 1
rst1.Edit
rst1![HEADING1] = "COMPONENT" & (j) & "_PERCENT"
rst1![HEADING2] = "COMPONENT" & (j) & "_NAME"
rst1![HEADING3] = "COMPONENT" & (j) & "_EHS"
rst1![HEADING4] = "COMPONENT" & (j) & "_CAS"
rst1.Update
rst2.MoveNext
Loop
j = 0
rst1.MoveNext
Loop
rst1.Close
Set rst1 = Nothing
Db.Close
Set Db = Nothing
End Function
PC