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("NoOfSessions"
= datPackage.Recordset("Sessions"
If chkATExpiry.Value = False Then
.Recordset("Expire"
= 0
End If
If chkATExpiry.Value = True Then
.Recordset("Expire"
= cldATCalendar.OutputText
End If
If chkATRegPrice.Value = True Then
.Recordset("Price"
= datPackage.Recordset("RegPrice"
.Recordset("Tax"
= datPackage.Recordset("RegTax"
.Recordset("Total"
= datPackage.Recordset("RegTotal"
- Val(txtATDiscount.Text)
End If
If chkATTCPrice.Value = True Then
.Recordset("Price"
= datPackage.Recordset("TCPrice"
.Recordset("Tax"
= datPackage.Recordset("TCTax"
.Recordset("Total"
= datPackage.Recordset("TCTotal"
- Val(txtATDiscount.Text)
End If
If chkATNoCharge.Value = True Then
.Recordset("Price"
= 0
.Recordset("Tax"
= 0
.Recordset("Total"
= 0
.Recordset("PaymentIDFK"
= 1 'default no charge sale as cash payment
End If
If chkATNoCharge.Value = False Then
.Recordset("PaymentIDKF"
= intPaymentID
End If
.Recordset("StaffIDFK"
= 4 'change this to the staff member variable
.Recordset("CustomerIDFK"
= intCustomerID
.Recordset("PackageIDFK"
= intPackageID
.Recordset.Update
End With
lstTSShoppingCart.AddItem datPackage.Recordset("PackageName"
MsgBox "Item Added to Shopping Cart.", 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...
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"
.Recordset("PackageID"
If Err.Number = 3265 Then
'this is sql server 7.0
.Recordset("PackageID"
ElseIf Err.Number <> 0 Then
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
End If
.Recordset("NoOfSessions"
If chkATExpiry.Value = False Then
.Recordset("Expire"
End If
If chkATExpiry.Value = True Then
.Recordset("Expire"
End If
If chkATRegPrice.Value = True Then
.Recordset("Price"
.Recordset("Tax"
.Recordset("Total"
End If
If chkATTCPrice.Value = True Then
.Recordset("Price"
.Recordset("Tax"
.Recordset("Total"
End If
If chkATNoCharge.Value = True Then
.Recordset("Price"
.Recordset("Tax"
.Recordset("Total"
.Recordset("PaymentIDFK"
End If
If chkATNoCharge.Value = False Then
.Recordset("PaymentIDKF"
End If
.Recordset("StaffIDFK"
.Recordset("CustomerIDFK"
.Recordset("PackageIDFK"
.Recordset.Update
End With
lstTSShoppingCart.AddItem datPackage.Recordset("PackageName"
MsgBox "Item Added to Shopping Cart.", 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...