|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
DataCombo and a TextBox
Hello!
I have a DataCombo and a TextBox on a form. I want the TextBox to display the data in the field next to the field of the DataCombo. When a line is picked in the DataCombo the same line in the next field should be shown in the TextBox. The field for the TextBox is named "FastenerCapacity" What should I add to this code I'm using for the DataCombo? Private Sub Form_Load() Dim sSql As String Dim rsInformation As New ADODB.Recordset Dim mCnn As New ADODB.Connection Dim strConn As String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Winsas\NewData.mdb;Persist Security Info=False" mCnn.Open strConn sSql = "SELECT * FROM Fasteners" rsInformation.CursorLocation = adUseClient rsInformation.Open sSql, mCnn, adOpenDynamic, adLockOptimistic Set cboFastenerType.RowSource = rsInformation cboFastenerType.ListField = "FastenerType" Set rsInformation = Nothing Set mCnn = Nothing End Sub |
|
#2
|
|||
|
|||
|
I don't understand what you want to do.
If you use an adodc and bind the datacombo and textbox to the appropriate columns the correct data should display automatically. |
|
#3
|
|||
|
|||
|
Hi Doug,
I deleted the code and now I'm using an adodc. Can you help to get the data to change in the textbox when I make a selection in the ComboBox. It must be something simple but I can't figure it out... |
|
#4
|
|||
|
|||
|
Try the onchange event of the combo box, maybe?
|
|
#5
|
|||
|
|||
|
Can you give me some help with that?
|
|
#6
|
|||
|
|||
|
In the code view for your form, select the datacombo1 control from the dropdown. The other dropdown will show all the events available for that control. Choose the Change event, and then write some code inside the event procedure that puts what you want into the text box.
This is if you're using VB6. Other versions of VB may need a different procedure. |
|
#7
|
|||
|
|||
|
Yes, it its VB6. I guessed it is the Change event I need but I don't know the code to use.
|
|
#8
|
||||
|
||||
|
just a word of advice, Knappe. You can set the data source for a text box to a particular field in a recordset. Your recordset will be zero based, as will the list. It shouldn't be too hard to make the next field appear in the text box that way.
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#9
|
|||
|
|||
|
I have set the data source for the textbox to the field I want. My problem is that the content of the textbox should change when I make a selection in the DataCombo. Now the textbox shows only the first line in the field.
|
|
#10
|
||||
|
||||
|
you won't want to use the _Change Event - try the _Click event for the box. Since the array is zero-based for the box, and for the recordset, you could do something like this in the _click event
Code:
rsRecordset.movefirst
rsrecordset.move (lstYourList.ListIndex)
'You may not need this line if you've set the textbox.text property = to the field you want in your recordset.
txtYourTextBox = rsRecordset("YourField")
The way I understand it, though, once you set the listbox = the Recordset field, as well as the textbox, then when you change the listbox, the textbox should change as well.... |
|
#11
|
|||
|
|||
|
Fisherman, I'm using a adodc and a DataCombo and TextBox, not a ListBox. How should I change the code? I tried formatting the one you gave, without success.
|
|
#12
|
||||
|
||||
|
ok... well, the ADODC control should function like the rsRecordset I had earlier, just replace rsRecordset with adoControl (whatever your control is called). As far as DataCombo, I must be lost here. Are you talking about a combo box?
|
|
#13
|
|||
|
|||
|
No, I'm trying to use a DataCombo. I don't know if I have to use a DataCombo. It can any kind of a list combobox that shows the contents of a db field. Now I think I'm lost here. I just can't get it working. Is there any examples for a thing like this? This can't be so difficult...
|
|
#14
|
||||
|
||||
|
have you tried something else besides the datacombo? I would try to help you with the datacombo, but I can't seem to find it in my toolbox, or under my components tab. I would recommend using something else.
|
|
#15
|
|||
|
|||
|
Look for the Microsoft Data List Controls 6.0 (SP3) (OLEDB) which has the datacombo and datalist components.
|