comnetlimited
Technical User
Hi folks,
I have two Access 2000 Tables, tblCustomers & tblcustomersledger.
I use a combo box to load list from table tblCustomers
ie. Rowsource =SELECT DISTINCTROW [tblcustomers].[customerid], [tblcustomers].[customername] AS customer FROM tblcustomers;
Now I want to use a command button, cmdSubmit, to first of all get the selected record identification and search the tblcustomerledgers table using a search criteria. If there is already a record of this criteria exist then it Updates the record otherwise it Adds new record to the table.
The problem is the RecordsAffected Option of ALWAYS return 0 and ADD records is not supported . This I found when break through the program.
here is part of the code:
Private Sub cmdSubmit_Click()
On Error GoTo Err_cmdSubmit_Click
Dim tempId
Dim rstNewLoan As ADODB.Recordset
Dim strSQL As String
Set rstNewLoan = New ADODB.Recordset
strSQL = "tblcustomersledger"
Set rstNewLoan = CurrentProject.Connection.Execute( _
"SELECT * FROM tblCustomersLedger" _
& " WHERE CustomerId='" & Me.cboCustomerId.Column(0) & "'AND [AmtOutStanding]<>0", tempId)
'tempId = rstNewLoan.Fields("Customerid")
If tempId <> 0 Then
If rstNewLoan.Supports(adUpdate) Then
With rstNewLoan
.Update
.Fields("LoanAmount") = .Fields("LoanAmount") + txtLoanAmount
.Fields("Interestdue") = .Fields("Interestdue") + Interest
.Fields("AmtOutStanding") = .Fields("AmtOutStanding") + Total
.Update
cmdReset_Click
End With
End If
rstNewLoan.Close
Set rstNewLoan = Nothing
Else
If rstNewLoan.Supports(adAddNew) Then
With rstNewLoan
.AddNew
.Fields("CustomerId") = cboCustomerId
.Fields("CustomerName") = lblCustomerName.Caption
.Fields("LoanAmount") = txtLoanAmount
.Fields("LoanDate") = Date
.Fields("InterestDue") = Interest
.Fields("TotalDue") = Total
.Fields("Datedue") = Date + 14
.Fields("AmtOutStanding") = Total
.Update
cmdReset_Click
End With
End If
rstNewLoan.Close
Set rstNewLoan = Nothing
End If ' TempId
Exit_cmdSubmit_Click:
Exit Sub
Err_cmdSubmit_Click:
MsgBox Err.Description
Resume Exit_cmdSubmit_Click
End Sub
Please HELP
I have two Access 2000 Tables, tblCustomers & tblcustomersledger.
I use a combo box to load list from table tblCustomers
ie. Rowsource =SELECT DISTINCTROW [tblcustomers].[customerid], [tblcustomers].[customername] AS customer FROM tblcustomers;
Now I want to use a command button, cmdSubmit, to first of all get the selected record identification and search the tblcustomerledgers table using a search criteria. If there is already a record of this criteria exist then it Updates the record otherwise it Adds new record to the table.
The problem is the RecordsAffected Option of ALWAYS return 0 and ADD records is not supported . This I found when break through the program.
here is part of the code:
Private Sub cmdSubmit_Click()
On Error GoTo Err_cmdSubmit_Click
Dim tempId
Dim rstNewLoan As ADODB.Recordset
Dim strSQL As String
Set rstNewLoan = New ADODB.Recordset
strSQL = "tblcustomersledger"
Set rstNewLoan = CurrentProject.Connection.Execute( _
"SELECT * FROM tblCustomersLedger" _
& " WHERE CustomerId='" & Me.cboCustomerId.Column(0) & "'AND [AmtOutStanding]<>0", tempId)
'tempId = rstNewLoan.Fields("Customerid")
If tempId <> 0 Then
If rstNewLoan.Supports(adUpdate) Then
With rstNewLoan
.Update
.Fields("LoanAmount") = .Fields("LoanAmount") + txtLoanAmount
.Fields("Interestdue") = .Fields("Interestdue") + Interest
.Fields("AmtOutStanding") = .Fields("AmtOutStanding") + Total
.Update
cmdReset_Click
End With
End If
rstNewLoan.Close
Set rstNewLoan = Nothing
Else
If rstNewLoan.Supports(adAddNew) Then
With rstNewLoan
.AddNew
.Fields("CustomerId") = cboCustomerId
.Fields("CustomerName") = lblCustomerName.Caption
.Fields("LoanAmount") = txtLoanAmount
.Fields("LoanDate") = Date
.Fields("InterestDue") = Interest
.Fields("TotalDue") = Total
.Fields("Datedue") = Date + 14
.Fields("AmtOutStanding") = Total
.Update
cmdReset_Click
End With
End If
rstNewLoan.Close
Set rstNewLoan = Nothing
End If ' TempId
Exit_cmdSubmit_Click:
Exit Sub
Err_cmdSubmit_Click:
MsgBox Err.Description
Resume Exit_cmdSubmit_Click
End Sub
Please HELP