Hello,
I am working with ADODB, and am trying to change the DataSource and
DataField properties of two text boxes on the fly. See article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;189852
I have the following code:
Option Explicit
Dim rsDummy As ADODB.Recordset
Dim rsSales As ADODB.Recordset
Private Sub chkNewSale_Click()
txtNewSaleID.Text = CInt(txtSaleID.Text) + 1
rsSales.AddNew
If txtSaleID.DataField = "Sale#" Then
txtSaleID.DataField = Empty
Set txtSaleID.DataSource = rsDummy
txtSaleID.DataField = "SaleID"
End If
If txtNewSaleID.DataField = "SaleID" Then
txtNewSaleID.DataField = Empty
Set txtNewSaleID.DataSource = rsSales
txtNewSaleID.DataField = "Sale#"
End If
chkNewSale.Enabled = False
End Sub
Private Sub Form_Load()
'initiate recordsets
Set rsDummy = New ADODB.Recordset
Set rsSales = New ADODB.Recordset
rsDummy.Open "Select * from tblDummy",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Darkstorm
Records.mdb;", adOpenStatic, adLockOptimistic
rsSales.Open "Select * from tblSales",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Darkstorm
Records.mdb;", adOpenStatic, adLockOptimistic
Set txtSaleID.DataSource = rsSales
txtSaleID.DataField = "Sale#"
Set txtNewSaleID.DataSource = rsDummy
txtNewSaleID.DataField = "SaleID"
Set txtCustID.DataSource = rsSales
txtCustID.DataField = "Customer#"
Set txtStockID.DataSource = rsSales
txtStockID.DataField = "Stock#"
End Sub
-Now, whenever I click on the chkNewSale checkbox, I immediately get the
following error:
"Run-time error '-2147217842 (80040e4e)': Operation was canceled."
Note: the 'rsSales.AddNew' seems to be the eorror-causing code.
Please help!