I am getting subscript out of range error when use for next loop through the Companycode array. I was trying earlier with 2 single dimension arrays. And had the same issue.
I am assigning duplicated companycodes to this array and want to run the queries based on different combination of companycodes. Am I assigning the array wrongly or am I looping the array the wrong way I? Any help is really appreciated. Thanks.
Dim strSql As String
Dim qdf As DAO.QueryDef
Dim rec As DAO.Recordset
Dim rec1, rec2, rec3 As DAO.Recordset
Dim CompanyCode() As Variant
Dim intRowCount As Integer
Dim i, j, lrow As Integer
Set rec3 = CurrentDb().OpenRecordset("select count(*) as Row_Count from tblgt_customer AS GC1 LEFT
JOIN tblGT_Customer AS GC2 ON GC1.ABN = GC2.ABN WHERE GC1.Customer<>[GC2].[Customer]")
lrow = rec3.Fields("Row_Count").Value
Set rec1 = CurrentDb().OpenRecordset("select gc1.company as company1,gc2.company as company2 from
tblgt_customer AS GC1 LEFT JOIN tblGT_Customer AS GC2 ON GC1.ABN = GC2.ABN WHERE GC1.Customer<>[GC2].
[Customer]")
CompanyCode = rec1.GetRows()
rec1.Close
For j = 0 To lrow
If CompanyCode(0, j) = "CICCO" And (CompanyCode(1, j) <> "CICCC" Or CompanyCode(1, j) <> "CAP") Then
Set qdf = CurrentDb.QueryDefs("qry_Customer_Dup_Check_7")
qdf.Execute
Set qdf = CurrentDb.QueryDefs("qry_Customer_Dup_Check_8")
qdf.Execute
ElseIf CompanyCode(0, j) = "CAP" And CompanyCode(1, j) <> "CICCC" Then
Set qdf = CurrentDb.QueryDefs("qry_Customer_Dup_Check_5")
qdf.Execute
Set qdf = CurrentDb.QueryDefs("qry_Customer_Dup_Check_6")
qdf.Execute
ElseIf CompanyCode(0, j) = "CICCC" Or CompanyCode(1, j) = "CICCC" Then
Set qdf = CurrentDb.QueryDefs("qry_Customer_Dup_Check_3")
qdf.Execute
Set qdf = CurrentDb.QueryDefs("qry_Customer_Dup_Check_4")
qdf.Execute
End If
Next j
Dim rec1, rec2, rec3 As DAO.Recordsetdeclares onlyrec3As DAO.Recordset. rec1 and rec2 are variants because no datatype has been assigned to them. Same forDim i, j, lrow As Integer. A datatype must be assigned to each variable individually.