Hi All
I've got a weird problem. When I try to compile the code below I get the error message 'Sub or Function not defined'. I'm using Access 2007.
What I'm trying to do is compare two recorsdsets and if it finds a difference, record the result line from both recordsets in a new table. This worked fine until I tried to go beyond more than 21 records from recordset 2 to publish to the Results table.
The problem arises in the 2nd INSERT INTO... statement. I get the error and it highlights the rec2(20) value. I can enter anything after it (it doesn't have to be a recordset value) but the error still occurs and it wont compile. If I close the statement at Rec2(20) it works fine.
I've no idea why. I can work around it but its a faff - is there something obvious I've missed?
I've got a weird problem. When I try to compile the code below I get the error message 'Sub or Function not defined'. I'm using Access 2007.
Code:
For x = 0 To 20
If Nz(rec1(x), "") <> Nz(rec2(x), "") Then
DoCmd.SetWarnings False
strSQL = "INSERT INTO tblResults ([Version], CUSTOMER_ID, CUSTOMER_NAME, CUST_LONG_NAME, STREET, CITY, POSTAL_CODE, COUNTRY_ID, AREA_MGR_ID, AREA_MGR, KAM_ID, KAM, SALES_REP_1_ID, SALES_REP_1, SALES_REP_2_ID, SALES_REP_2, SALES_REP_3_ID, SALES_REP_3, SALES_REP_4_ID, SALES_REP_4, SALES_REP_5_ID, SALES_REP_5) " & _
"VALUES ('" & intVersion & "', '" & rec1(0) & "', '" & rec1(1) & "', '" & rec1(2) & "', '" & rec1(3) & "', '" & rec1(4) & "', '" & rec1(5) & "', '" & rec1(6) & "', '" & rec1(7) & "', '" & rec1(8) & "', '" & rec1(9) & "', '" & rec1(10) & "', '" & rec1(11) & "', '" & rec1(12) & "', '" & rec1(13) & "', '" & rec1(14) & "', '" & rec1(15) & "', '" & rec1(16) & "', '" & rec1(17) & "', '" & rec1(18) & "', '" & rec1(19) & "', '" & rec1(20) & "');"
DoCmd.RunSQL strSQL
strSQL = "INSERT INTO tblResults ([Version], CUSTOMER_ID, CUSTOMER_NAME, CUST_LONG_NAME, STREET, CITY, POSTAL_CODE, COUNTRY_ID, AREA_MGR_ID, AREA_MGR, KAM_ID, KAM, SALES_REP_1_ID, SALES_REP_1, SALES_REP_2_ID, SALES_REP_2, SALES_REP_3_ID, SALES_REP_3, SALES_REP_4_ID, SALES_REP_4, SALES_REP_5_ID, SALES_REP_5, [Modified], [Modified By]) " & _
"VALUES ('" & intVersion & "', '" & rec2(0) & "', '" & rec2(1) & "', '" & rec2(2) & "', '" & rec2(3) & "', '" & rec2(4) & "', '" & rec2(5) & "', '" & rec2(6) & "', '" & rec2(7) & "', '" & rec2(8) & "', '" & rec2(9) & "', '" & rec2(10) & "', '" & rec2(11) & "', '" & rec2(12) & "', '" & rec2(13) & "', '" & rec2(14) & "', '" & rec2(15) & "', '" & rec2(16) & "', '" & rec2(17) & "', '" & rec2(18) & "', '" & rec2(19) & "', '" & rec2(20) & "', '" & rec(23) & "', '" & rec(24) & "');"
DoCmd.RunSQL strSQL
x = 0
DoCmd.SetWarnings True
GoTo NextRecord
End If
Next x
The problem arises in the 2nd INSERT INTO... statement. I get the error and it highlights the rec2(20) value. I can enter anything after it (it doesn't have to be a recordset value) but the error still occurs and it wont compile. If I close the statement at Rec2(20) it works fine.
I've no idea why. I can work around it but its a faff - is there something obvious I've missed?