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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way.....

Status
Not open for further replies.

Collin79

Programmer
Dec 31, 2000
31
MX
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???
 
The first thing that comes to mind is that the recordset is only created if the boundtext is GNP, but the iteration of controls to set datafield is done in every case. Should this be the caase? It seems a bit strange to me.

Hope I'm not on the wrong track here. I'm afraid I can't help you with code for checking if a recordset is open or not.

Mats
 
try this:

if rsPreliminar.adstate = adstateopen then
with rstPreliminar
.update
.close
end with
end if

Another Matt

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top