I use this code
Works fine except if "rsAp!checkno" is empty
I get an error on this line,
"Non-nullable column cannot be updated to null"
the rsT.Reccount =1, rst!amount = Null
so, it seem to return a record but the totamount is Null. but there are no records in this table where the amount field is empty, or even 0.
I don't understand why it's not finding the correct record. The sql is preformed on the the same table.
I changed the code to this and now it works,
I'm just curious why the first code I used didn't work!
Code:
Dim rsRpt As New ADODB.Recordset, rsAp As New ADODB.Recordset, rsT As New ADODB.Recordset, checkNo As String
rsAp.Open "Select distinct k_vendor,k_name, checkno from aptranshold WHERE (finalized='N') and chk_selct='Y' AND cmab_schd='" & dcSchedno.Text & "' ORDER BY k_name", conCnn, adOpenStatic, adLockOptimistic
With rsRpt
.Fields.Append "LineNo", adVarChar, 3
.Fields.Append "VenName", adVarChar, 60
.Fields.Append "Amount", adDouble
.Fields.Append "CheckNo", adVarChar, 12
.Open
'
Dim cntr As Integer
cntr = 1
Do While Not rsAp.EOF
'checkNo = IIf(IsNull(rsAp!checkNo), "", rsAp!checkNo)
rsT.Open "select sum(amount) as totamount from aptranshold WHERE (finalized='N') and chk_selct='Y' and cmab_schd='" & dcSchedno.Text & "' and k_vendor='" & rsAp!k_vendor & "' AND checkno='" & rsAp!checkNo & "'", conCnn, adOpenStatic, adLockReadOnly, adCmdText
.AddNew
!lineno = CStr(cntr) & "."
!VenName = rsAp!k_name
!amount = rsT!totamount
!checkNo = IIf(IsNull(rsAp!checkNo), "", rsAp!checkNo)
.Update
rsT.Close
cntr = cntr + 1
rsAp.MoveNext
Loop
End With
I get an error on this line,
Code:
!amount = rsT!totamount
the rsT.Reccount =1, rst!amount = Null
so, it seem to return a record but the totamount is Null. but there are no records in this table where the amount field is empty, or even 0.
I don't understand why it's not finding the correct record. The sql is preformed on the the same table.
I changed the code to this and now it works,
Code:
Dim rsRpt As New ADODB.Recordset, rsAp As New ADODB.Recordset, rsT As New ADODB.Recordset
rsAp.Open "Select distinct k_vendor,k_name, checkno,sum(amount) as totamount from aptranshold WHERE (finalized='N') and chk_selct='Y' AND cmab_schd='" & dcSchedno.Text & "' GROUP BY k_vendor,k_name,checkno ORDER BY k_name", conCnn, adOpenStatic, adLockOptimistic
With rsRpt
.Fields.Append "LineNo", adVarChar, 3
.Fields.Append "VenName", adVarChar, 60
.Fields.Append "Amount", adDouble
.Fields.Append "CheckNo", adVarChar, 12
.Open
'
Dim cntr As Integer
cntr = 1
Do While Not rsAp.EOF
.AddNew
!lineno = CStr(cntr) & "."
!VenName = rsAp!k_name
'!amount = rsT!totamount
!amount = rsAp!totamount
!checkNo = IIf(IsNull(rsAp!checkNo), "", rsAp!checkNo)
.Update
cntr = cntr + 1
rsAp.MoveNext
Loop
End With