Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add New not occuring, even though AddNew function executes error free.

Status
Not open for further replies.

Ads

Programmer
May 29, 2001
17
0
0
CA
Hey...
I have a simple command button that adds new transactions to a customer table called datTransactionPackage. I've called the AddNew event for the the recordsource and append the information at runtime.

Following is the add event called when "Add to Shopping Cart" is clicked.

Private Sub cmdATShoppingCart_Click()
On Error Resume Next

Dim intCustomerID As Integer
Dim intPackageID As Integer
Dim intLotionID As Integer
Dim intPaymentID As Integer
Dim curDiscount As Currency
Dim strSQLPackage As String
Dim strSQLLotion As String
Dim srtSQLCustomerPackage As String


strSQLCustomerPackage = "SELECT TransactionPackage.* " & _
"FROM TransactionPackage;"

datCustomerPackage.RecordSource = srtSQLCustomerPackage
datCustomerPackage.Refresh

If cboATLastName.ListIndex = -1 Then
MsgBox "A Customer must be selected from the drop down list.", vbOKOnly
Exit Sub
Else
intCustomerID = cboATLastName.ItemData(cboATLastName.ListIndex)
End If

intPaymentID = cboATPaymentType.ItemData(cboATPaymentType.ListIndex)

intPackageID = lstATPackage.ItemData(lstATPackage.ListIndex)

strSQLPackage = "SELECT Package.* " & _
"FROM Package " & _
"Where Package.PackageID = " & intPackageID & " ;"

datPackage.RecordSource = strSQLPackage
datPackage.Refresh


With datCustomerPackage
.Recordset.AddNew
.Recordset("CustomerID") = intCustomerID
.Recordset("PackageID") = intPackageID

If Err.Number = 3265 Then
'this is sql server 7.0
.Recordset("PackageID") = CLng(datPackage.Recordset("PackageID").Value)
ElseIf Err.Number <> 0 Then
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
End If


.Recordset(&quot;NoOfSessions&quot;) = datPackage.Recordset(&quot;Sessions&quot;)

If chkATExpiry.Value = False Then
.Recordset(&quot;Expire&quot;) = 0
End If

If chkATExpiry.Value = True Then
.Recordset(&quot;Expire&quot;) = cldATCalendar.OutputText
End If

If chkATRegPrice.Value = True Then
.Recordset(&quot;Price&quot;) = datPackage.Recordset(&quot;RegPrice&quot;)
.Recordset(&quot;Tax&quot;) = datPackage.Recordset(&quot;RegTax&quot;)
.Recordset(&quot;Total&quot;) = datPackage.Recordset(&quot;RegTotal&quot;) - Val(txtATDiscount.Text)
End If

If chkATTCPrice.Value = True Then
.Recordset(&quot;Price&quot;) = datPackage.Recordset(&quot;TCPrice&quot;)
.Recordset(&quot;Tax&quot;) = datPackage.Recordset(&quot;TCTax&quot;)
.Recordset(&quot;Total&quot;) = datPackage.Recordset(&quot;TCTotal&quot;) - Val(txtATDiscount.Text)
End If

If chkATNoCharge.Value = True Then
.Recordset(&quot;Price&quot;) = 0
.Recordset(&quot;Tax&quot;) = 0
.Recordset(&quot;Total&quot;) = 0
.Recordset(&quot;PaymentIDFK&quot;) = 1 'default no charge sale as cash payment
End If

If chkATNoCharge.Value = False Then
.Recordset(&quot;PaymentIDKF&quot;) = intPaymentID
End If

.Recordset(&quot;StaffIDFK&quot;) = 4 'change this to the staff member variable
.Recordset(&quot;CustomerIDFK&quot;) = intCustomerID
.Recordset(&quot;PackageIDFK&quot;) = intPackageID
.Recordset.Update

End With
lstTSShoppingCart.AddItem datPackage.Recordset(&quot;PackageName&quot;)

MsgBox &quot;Item Added to Shopping Cart.&quot;, vbOKOnly
End Sub

My Question: After the add new, and the final message box indicates a new item has been added, my table does not look like it added a record at all. Why?

ps-I was getting error 3265 because of SQL 7.0 but thought I fixed it... might be part of the problem.

Thanks for your help...

 
Check for an error after you update the recordset. Is there one?

Comment out
Code:
On Error Resume Next
to see what is happening?

I don't believe you're handling error 3265 correctly. My ADO Error Reference is saying that a field is probably misspelled. If that's the case, you're not handling the error in the matter you should be. Since you're resuming execution when a run-time error occurs, you're probably getting an error in your error handler that isn't being trapped. I could be wrong on that though.

I hope that helps aim you in the right direction.

--
Jonathan
 
I had the same type of problem. Through code I could not see the new records added until I issued a REQUERY command.

Hope this is helpful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top