Home > Archive > Visual Basic > October 2004 > ado combo & text box dinding error?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ado combo & text box dinding error?
|
|
|
| Hi,
I have a problem with biding(I think) a combo box with text boxes.
The combo and text boxes on my form are loaded with the correct data.
But, when I click on the combo box and select a different data member
the combo box reflects the selected change(text changes) OK but my
text boxes do not. - the text is unchanged.
I have tried a number of variations of code with no luck.
In my code below if I change the customerID combo box value the first
and last names do not change
Any help as to how to fix this problem will be appreciated
regards
Eric
my form load:
call creatCon
Do Until rsCustomer.EOF
If Not IsNull(rsCustomer!CustomerID) Then
cboCustomerID.AddItem rsCustomer!CustomerID
rsCustomer.MoveNext
Loop
Set cboCustomerID.DataSource = rsCustomer
cboCustomerID.DataField = "CustomerID"
Set txtCustomerFirstName.DataSource = rsCustomer
txtCustomerFirstName.DataField = "CustomerFirstName"
Set txtCustomerLastName.DataSource = rsCustomer
txtCustomerLastName.DataField = "CustomerLastName"
If cboCustomerID.ListCount > 0 Then
rsCustomer.MoveFirst
cboCustomerID.Text = rsCustomer!CustomerID
End If
my Bas module:
Public cnCustomer As New ADODB.Connection
Public rsCustomer As New ADODB.Recordset
Public strConn As String
Public Function createCon()
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=G:\INCAT.mdb;Mode=ReadWrite;Persist Security Info=False"
Set cnCustomer = New ADODB.Connection
Set rsCustomer = New ADODB.Recordset
Debug.Print "Connection Object Created"
If cnCustomer.State = adStateClosed Then
cnCustomer.CursorLocation = adUseClient
cnCustomer.Open strConn
End If
rsCustomer.Open "SELECT * FROM tblCustomer ORDER BY CustomerID",
cnCustomer, adOpenStatic, adLockBatchOptimistic, adCmdText
Debug.Print "Recordset Customer Created"
Set rsCustomer.ActiveConnection = Nothing
cnCustomer.Close
End Function
| |
|
|
What code do you have in cboCustomerID_Click() event?
If none, you should have some.....
--- Andy
>-----Original Message-----
>Hi,
>I have a problem with biding(I think) a combo box with
text boxes.
>The combo and text boxes on my form are loaded with the
correct data.
>But, when I click on the combo box and select a different
data member
>the combo box reflects the selected change(text changes)
OK but my
>text boxes do not. - the text is unchanged.
>I have tried a number of variations of code with no luck.
>In my code below if I change the customerID combo box
value the first
>and last names do not change
>Any help as to how to fix this problem will be appreciated
>regards
>Eric
>
>my form load:
>
> call creatCon
> Do Until rsCustomer.EOF
> If Not IsNull(rsCustomer!CustomerID) Then
>cboCustomerID.AddItem rsCustomer!CustomerID
> rsCustomer.MoveNext
> Loop
> Set cboCustomerID.DataSource = rsCustomer
> cboCustomerID.DataField = "CustomerID"
> Set txtCustomerFirstName.DataSource =
rsCustomer
> txtCustomerFirstName.DataField = "CustomerFirstName"
> Set txtCustomerLastName.DataSource = rsCustomer
> txtCustomerLastName.DataField = "CustomerLastName"
>
> If cboCustomerID.ListCount > 0 Then
> rsCustomer.MoveFirst
> cboCustomerID.Text = rsCustomer!CustomerID
> End If
>
>my Bas module:
>
>Public cnCustomer As New ADODB.Connection
>Public rsCustomer As New ADODB.Recordset
>Public strConn As String
>
>Public Function createCon()
>strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
>Source=G:\INCAT.mdb;Mode=ReadWrite;Persist Security
Info=False"
> Set cnCustomer = New ADODB.Connection
> Set rsCustomer = New ADODB.Recordset
>
> Debug.Print "Connection Object Created"
> If cnCustomer.State = adStateClosed Then
> cnCustomer.CursorLocation = adUseClient
> cnCustomer.Open strConn
> End If
> rsCustomer.Open "SELECT * FROM tblCustomer ORDER BY
CustomerID",
>cnCustomer, adOpenStatic, adLockBatchOptimistic, adCmdText
> Debug.Print "Recordset Customer Created"
>
> Set rsCustomer.ActiveConnection = Nothing
> cnCustomer.Close
>
>End Function
>.
>
| |
|
| "Andy" <Andrzej7@hotmail.com> wrote in message news:<150a01c4babd$d53ce6a0$a301280a@phx.gbl>...[color=darkred]
> What code do you have in cboCustomerID_Click() event?
> If none, you should have some.....
>
> --- Andy
>
> text boxes.
> correct data.
> data member
> OK but my
> value the first
> rsCustomer
> Info=False"
> CustomerID",
Thanks for reply.
But add what?
tried variations of populating boxes with recorset - messy
also tried moving the record in the boxes to the selected one which I
assume is what your supposed to do, again this does'nt work either
any further help appreciated
regards
Eric
| |
|
| Eric,
When you click on the combo box, you need to move to the related record in
order to make that record the current record. So in the Click event of the
Combo, do something like:
rsCustomer.MoveFirst
Do While not rsCustomer.EOF
If rsCustomer!CustomerID = cboCustomer.List(cboCustomer.ListIndex) Then
'Found the matching record
Exit Do
End If
rsCustomer.MoveNext
Loop
You can also use the Filter method or Find as you prefer.
You may want to add code to check the status of the current record to see if
it has been changed before moving off the current recordset and performing
the appropriate Update or Cancel methods on it.
HTH,
CF
"Eric" <estacey@chariot.net.au> wrote in message
news:d16bbdbf.0410250928.23acd472@posting.google.com...
> Hi,
> I have a problem with biding(I think) a combo box with text boxes.
> The combo and text boxes on my form are loaded with the correct data.
> But, when I click on the combo box and select a different data member
> the combo box reflects the selected change(text changes) OK but my
> text boxes do not. - the text is unchanged.
> I have tried a number of variations of code with no luck.
> In my code below if I change the customerID combo box value the first
> and last names do not change
> Any help as to how to fix this problem will be appreciated
> regards
> Eric
>
> my form load:
>
> call creatCon
> Do Until rsCustomer.EOF
> If Not IsNull(rsCustomer!CustomerID) Then
> cboCustomerID.AddItem rsCustomer!CustomerID
> rsCustomer.MoveNext
> Loop
> Set cboCustomerID.DataSource = rsCustomer
> cboCustomerID.DataField = "CustomerID"
> Set txtCustomerFirstName.DataSource = rsCustomer
> txtCustomerFirstName.DataField = "CustomerFirstName"
> Set txtCustomerLastName.DataSource = rsCustomer
> txtCustomerLastName.DataField = "CustomerLastName"
>
> If cboCustomerID.ListCount > 0 Then
> rsCustomer.MoveFirst
> cboCustomerID.Text = rsCustomer!CustomerID
> End If
>
> my Bas module:
>
> Public cnCustomer As New ADODB.Connection
> Public rsCustomer As New ADODB.Recordset
> Public strConn As String
>
> Public Function createCon()
> strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=G:\INCAT.mdb;Mode=ReadWrite;Persist Security Info=False"
> Set cnCustomer = New ADODB.Connection
> Set rsCustomer = New ADODB.Recordset
>
> Debug.Print "Connection Object Created"
> If cnCustomer.State = adStateClosed Then
> cnCustomer.CursorLocation = adUseClient
> cnCustomer.Open strConn
> End If
> rsCustomer.Open "SELECT * FROM tblCustomer ORDER BY CustomerID",
> cnCustomer, adOpenStatic, adLockBatchOptimistic, adCmdText
> Debug.Print "Recordset Customer Created"
>
> Set rsCustomer.ActiveConnection = Nothing
> cnCustomer.Close
>
> End Function
|
|
|
|
|