Hi, I'm using a DataCombo, in it, depending it's boudtext it will bind all my text box on my form, as follows:
Private rsPreliminar As New ADODB.Recordset
Private Sub DataCombo1_LostFocus()
If DataCombo1.BoundText = "GNP" Then
'Open recordset directly
With rsPreliminar
.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data Source=C:\sia\sia.mdb;Persist Security Info=False"
.Source = "SELECT Fiel1, Field2, Field3 FROM Table"
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.CursorType = adOpenForwardOnly
.LockType = adLockOptimistic
.Open
End With
End If
'Iterate the Controls collection
For Each ctlTextbox In Me.Controls
If TypeOf ctlTextbox Is TextBox Then
With ctlTextbox
Set .DataSource = rsPreliminar
.DataField = Mid(.Name, 4)
End With
End If
Next ctlTextbox
'Bind the ADODC for navigation
Set AdPreliminar.Recordset = rsPreliminar
End Sub
It works ok, but when I choose other text on Datacombo an error occurs:
Run-time error '3705'
Operation is not allowed when the object is open
I've tried something like this:
if rsPreliminar.open then
rsPreliminar.close
End If
but it doesn't work
Any hint???
Private rsPreliminar As New ADODB.Recordset
Private Sub DataCombo1_LostFocus()
If DataCombo1.BoundText = "GNP" Then
'Open recordset directly
With rsPreliminar
.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data Source=C:\sia\sia.mdb;Persist Security Info=False"
.Source = "SELECT Fiel1, Field2, Field3 FROM Table"
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.CursorType = adOpenForwardOnly
.LockType = adLockOptimistic
.Open
End With
End If
'Iterate the Controls collection
For Each ctlTextbox In Me.Controls
If TypeOf ctlTextbox Is TextBox Then
With ctlTextbox
Set .DataSource = rsPreliminar
.DataField = Mid(.Name, 4)
End With
End If
Next ctlTextbox
'Bind the ADODC for navigation
Set AdPreliminar.Recordset = rsPreliminar
End Sub
It works ok, but when I choose other text on Datacombo an error occurs:
Run-time error '3705'
Operation is not allowed when the object is open
I've tried something like this:
if rsPreliminar.open then
rsPreliminar.close
End If
but it doesn't work
Any hint???