VB6 Databound text boxes cease to coordinate with datagrid control
- From: Lamont <Lamont@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 10 Apr 2007 00:14:00 -0700
Data from an Access database in my app fills a record set and this recordset
is the data source to multiple text boxes, and a datagird. It worked fine,
with text box values changing in synchronization with changes in the selected
row in the datagrid. Also, entries in the text box were automatically shown
in the corresponding grid dell. Then, suddenly, the text boxes display
nothing, while the data grid continues to work OK. I have reinstalled the
MS Access database and VB, supposing that the work software had become
corrupted.
I have coded a tiny demo app to show the problem after the ====== line below.
Thank you for kind help. Lamont
Step 1. Create recordset from the database. This works and fills recordset
with data.
Step 2. Set the record set as datasource for a data grid. This works &
fills grid.
dgMsg.ClearFields 'dbMsg is the data bound
data grid.
Set dgMsg.DataSource = rsVotersLocal
Step 3. Set textboxes' data source from the recordset
Set txtVoterID.DataSource = rsVotersLocal ' txtVoterID, txtFirstName
etc. are the text boxes
Set txtVoterID.DataSource = rsVotersLocal
Set txtFirstName.DataSource = rsVotersLocal
Code for demo app==================================
Private strCnn As String
Private cnnVotersLocal As ADODB.Connection
Private rsVotersLocal As ADODB.Recordset
Private Sub Form_Load()
strCnn = "Provider = Microsoft.jet.OLEDB.4.0;Data Source=" & App.Path &
"\Demo.mdb"
Set cnnVotersLocal = New ADODB.Connection
cnnVotersLocal.Open (strCnn)
Set rsVotersLocal = New ADODB.Recordset
Dim strSQL As String
strSQL = "Select voterid, firstname, lastname from voterslocal order by
lastname, firstname;"
With rsVotersLocal
.ActiveConnection = cnnVotersLocal
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Properties("IRowsetIdentity") = True
.Open strSQL, , , , adCmdText
End With
dgMsg.ClearFields
Set dgMsg.DataSource = rsVotersLocal
Set txtVoterID.DataSource = rsVotersLocal 'Textbox
Set txtFirstName.DataSource = rsVotersLocal 'Textbox
Set txtLastName.DataSource = rsVotersLocal 'Textbox
End Sub
'No Code after form load. Just type in text boxes and select rows in the
grid.
--
Lamont Phemister
.
- Prev by Date: Re: Using resource file to store images
- Next by Date: Re: How to suspend Windows?
- Previous by thread: Re: Runtime error 2147467259 {8000-4005}
- Next by thread: XML, DOM export
- Index(es):
Relevant Pages
|
|