KevinSlater
Registered User.
- Local time
- Today, 02:13
- Joined
- Aug 5, 2005
- Messages
- 249
Hi,
i have the below code in a Access 2003 module, but when i run the code i get the following error message: runtime error: 94, invalid use of Null, and when i click debug it highlights this line: x = x + rs(fArr(i))
Any suggestions on how to fix this would be great?.
Sub delZ()
Dim rs As DAO.Recordset, j As Integer, x As Long, fArr(), i As Integer
Set rs = CurrentDb.OpenRecordset("DATA-FORECAST_UPDATE")
rs.MoveFirst
i = 0
For j = 0 To rs.Fields.Count - 1
If InStr(rs(j).Name, "_QTY") > 0 Or InStr(rs(j).Name, "_VALUE") > 0 _
Or InStr(rs(j).Name, "PROMO_PRICE") > 0 Or InStr(rs(j).Name, "ACT") > 0 Or InStr(rs(j).Name, "BSALES") > 0 Then
ReDim Preserve fArr(i)
fArr(i) = rs(j).Name
i = i + 1
End If
Next
Do Until rs.EOF
x = 0
For i = 0 To UBound(fArr)
x = x + rs(fArr(i))
Next
If x = 0 Then rs.Delete
rs.MoveNext
Loop
rs.Close
End Sub
want im wanting to do is look for the follwing field names: FORECAST_1_BASE_QTY, FORECAST_1_BASE_VALUE, FORECAST_1_PROMO_QTY, FORECAST_1_PROMO_VALUE, PD1ACTVAL, BSALES1, PD1ACT in a table and should all of these fileds be empty or 0 on a record then that record should be deleted but only if all fields are empty, if one field has data then the record should not be deleted.
i have the below code in a Access 2003 module, but when i run the code i get the following error message: runtime error: 94, invalid use of Null, and when i click debug it highlights this line: x = x + rs(fArr(i))
Any suggestions on how to fix this would be great?.
Sub delZ()
Dim rs As DAO.Recordset, j As Integer, x As Long, fArr(), i As Integer
Set rs = CurrentDb.OpenRecordset("DATA-FORECAST_UPDATE")
rs.MoveFirst
i = 0
For j = 0 To rs.Fields.Count - 1
If InStr(rs(j).Name, "_QTY") > 0 Or InStr(rs(j).Name, "_VALUE") > 0 _
Or InStr(rs(j).Name, "PROMO_PRICE") > 0 Or InStr(rs(j).Name, "ACT") > 0 Or InStr(rs(j).Name, "BSALES") > 0 Then
ReDim Preserve fArr(i)
fArr(i) = rs(j).Name
i = i + 1
End If
Next
Do Until rs.EOF
x = 0
For i = 0 To UBound(fArr)
x = x + rs(fArr(i))
Next
If x = 0 Then rs.Delete
rs.MoveNext
Loop
rs.Close
End Sub
want im wanting to do is look for the follwing field names: FORECAST_1_BASE_QTY, FORECAST_1_BASE_VALUE, FORECAST_1_PROMO_QTY, FORECAST_1_PROMO_VALUE, PD1ACTVAL, BSALES1, PD1ACT in a table and should all of these fileds be empty or 0 on a record then that record should be deleted but only if all fields are empty, if one field has data then the record should not be deleted.