what im trying to get in this code is that, first i search if theres a same reocrd existing on my database,on a field on my table, field name Status, i conditioned it if the status is approved this code below will execute. i must update the existing data on every recordcount that it found,this code below loops but i dont know how to array database fields on my loop so i can proceed to the next recordcount or next data that corresponds to the recordcount.
If rs.State = adStateOpen Then rs.Close
rs.CursorLocation = adUseClient
rs.Open "Select * from budget_history where voucherNo ='" & txtDVno.Text & "'", cn, adOpenDynamic, adLockOptimistic
If rs.RecordCount > 0 Then
For p = 1 To rs.RecordCount
aMt = p(rs!amount)'<< after the 1st loop an error pops up "type mismatch" i just want the data to change after it loops according to the array.
wbr = p(rs!wbrNo)
Desc = p(rs!Accdescription)
If Desc = "Direct material" Then
If rs.State = adStateOpen Then rs.Close
rs.CursorLocation = adUseClient
rs.Open "select * from wbr where wbrno = '" & wbr & "'", cn, adOpenDynamic, adLockOptimistic
If rs.RecordCount > 0 Then
a = rs!dmbal
b = rs!dmbal + aMt
c = rs!deductionTotal - aMt
d = rs!DMdeduct - aMt
cn.Execute "Update wbr set DMbal = '" & b & "', deductionTotal = '" & c & "', DMdeduct = '" & d & "' where wbrNo = '" & wbr & "'"
a = 0
b = 0
c = 0
d = 0
End If
End If
If Desc = "Direct labor" Then
If rs.State = adStateOpen Then rs.Close
rs.CursorLocation = adUseClient
rs.Open "select * from wbr where wbrno = '" & wbr & "'", cn, adOpenDynamic, adLockOptimistic
If rs.RecordCount > 0 Then
a = rs!DLbal
b = rs!DLbal + aMt
c = rs!deductionTotal - aMt
d = rs!DLdeduct - aMt
cn.Execute "Update wbr set DLbal = '" & b & "', deductionTotal = '" & c & "', DLdeduct = '" & d & "' where wbrNo = '" & wbr & "'"
a = 0
b = 0
c = 0
d = 0
End If
End If
If Desc = "Overhead" Then
If rs.State = adStateOpen Then rs.Close
rs.CursorLocation = adUseClient
rs.Open "select * from wbr where wbrno = '" & wbr & "'", cn, adOpenDynamic, adLockOptimistic
If rs.RecordCount > 0 Then
a = rs!OHbal
b = rs!OHbal + aMt
c = rs!deductionTotal - aMt
d = rs!OHdeduct - aMt
cn.Execute "Update wbr set OHbal = '" & b & "', deductionTotal = '" & c & "', OHdeduct = '" & d & "' where wbrNo = '" & wbr & "'"
a = 0
b = 0
c = 0
d = 0
End If
End If
rs.NextRecordset
Next
End If