Solved

datacombo listview (change) according predefined choice

Posted on 2006-07-08
21
282 Views
Last Modified: 2013-12-25
Hi,

In a combobox I need to make a selection (of a predefined table in access), for example "customer".
If I use the command button next to it, there is a datacombo which should be filled with data from the customer table.

------------ so far no problem---------------

if i make a different choice in the combobox and press the cmd again there is no change in the datacombo.
I expect to load different data in it from a different table in my access database

I already tried with two different ADODC connectors but this doesnt seems to work!

Is there anybody who could provide me some code plz????
0
Comment
Question by:Masterofdisaster1020
  • 9
  • 6
  • 4
  • +1
21 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17066179
Post your code and we can probalby point out the problem.  

P.S. There is no need to use the ADO data control.
0
 
LVL 2

Author Comment

by:Masterofdisaster1020
ID: 17067438
here it is:

Private Sub Command1_Click()
Dim zoek As String
zoek = Combo1.Text

If zoek = "Klant" Then
    Adodc1.RecordSource = "klanten"
    'DataCombo1.DataSource = Adodc1
    DataCombo.RowSource = Adodc1
    DataCombo1.DataField = "klant"
End If

If zoek = "Vloer" Then
    Adodc2.RecordSource = "tabel1"
    'DataCombo1.DataSource = Adodc2
    DataCombo1.RowSource = Adodc2
    DataCombo1.DataField = "veld1"
End If
End Sub
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17068490
I am sorry, but I don't use the DataCombo, let alone the ADO Data Control.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:pradapkumar
ID: 17072681
Private Sub Command1_Click()
Dim zoek As String
zoek = Combo1.Text

If zoek = "Klant" Then
    Adodc1.RecordSource = "klanten"
    'DataCombo1.DataSource = Adodc1
    DataCombo.RowSource = Adodc1
    DataCombo1.DataField = "klant"
    DataCombo1.ReFill                            'Add this line
End If

If zoek = "Vloer" Then
    Adodc2.RecordSource = "tabel1"
    'DataCombo1.DataSource = Adodc2
    DataCombo1.RowSource = Adodc2
    DataCombo1.DataField = "veld1"
    DataCombo1.ReFill                            'Add this line
End If
End Sub

I hope this will help you.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17074707
pradapkumar,

I suspect you mean:
DataCombo1.Refresh
0
 
LVL 9

Expert Comment

by:pradapkumar
ID: 17078841
The ReFill method is different than the standard Refresh method, which just forces a Repaint event.
0
 
LVL 9

Expert Comment

by:pradapkumar
ID: 17078847
But if you use Refresh method on a Data control to open or reopen the database (if the DatabaseName, ReadOnly, Exclusive, or Connect property settings have changed) and rebuild the dynaset in the control's Recordset property.

0
 
LVL 9

Expert Comment

by:pradapkumar
ID: 17078851
so you can use any one of the above which will work for you.
0
 
LVL 2

Author Comment

by:Masterofdisaster1020
ID: 17080601
Hi,

pradapkumar, unfortunally the code you provide me, does not solve the problem.
I even tried to rephrase the adodc connector cause I expected the problem there, i even tried with datacombo1.refresh but no solution!
see example:

'Dim zoek As String
'zoek = Combo1.Text

'If zoek = "Klant" Then
   
    'Adodc1.RecordSource = "select * from Klanten"
    'DataCombo1.DataField = "klant"
    'DataCombo1.ListField = "Klant"
    'DataCombo1.ReFill                            'Add this line
'End If

'If zoek = "Vloer" Then
   
    'Adodc2.RecordSource = "select * from Tabel1"
    'DataCombo1.DataField = "Veld1"
    'DataCombo1.ListField = "Veld1"
    'DataCombo1.ReFill                            'Add this line
   
'End If

In the mean time I was looking over the EE site and found this article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;230167&Product=vbb
provided by user "emoreau".

So I started working for a "workaround" and found it!
see example:
Private Sub Combo1_Click()
Dim zoek As String
zoek = Combo1.Text

If zoek = "Klant" Then    
DataCombo1.Visible = True
DataCombo2.Visible = False
End If

If zoek = "Vloer" Then
DataCombo1.Visible = False
DataCombo2.Visible = True
End If

End Sub

with 2 Adodc connectors pointing to a different table and 2 different datacombo's bounded to the 2 different connectors,the problem was solved.

Thanx a lot anyway,
both of you

0
 
LVL 2

Author Comment

by:Masterofdisaster1020
ID: 17080619
0
 
LVL 9

Expert Comment

by:pradapkumar
ID: 17088042
This is also a alternate way.
Use only one ordinary combo control instead of datacombo which is not so much flexible
And also add the adodb library through Project->Libraries Menu items from VB6 IDE.

Private Sub Combo1_Click()
Dim zoek As String,strQuerry as String
Dim con As ADODB.Connection, rs As ADODB.Recordset
con.Open <Connection which may be generated by your adodc control>
zoek = Combo1.Text
Select Case
Case "Klant"
      strSQL = "select klant from Klanten"
Case "Vloer"  
      strSQL = "select veld1 from Tabel1"  
End Select
set rs = con.Execute(strSQL)
With Combo2
    .Clear
    while Not rs.EOf
        .AddItem rs.Fields(0).Value
        rs.MoveNext
    Wend
End With
End Sub

Now your combo2 will have new list.
Programming through code with generic controls will give u the greater flexibility instead of using DatabindCOmbo or ADODC controls.

I am always relying on the above approach only and I had developed all the projects in the above way. To make the connection & recordset objects common to all forms declare them in a Module as with Public Keyword. So you can utilise that conneciton & Recordset objects globally.

with regards.
Pradap @};-
0
 
LVL 9

Expert Comment

by:pradapkumar
ID: 17088053
Sorry read this as
>>con.Open <Connection which may be generated by your adodc control>


con.Open <Connection String which may be generated by your adodc control>
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17090235
And it would probably help to initialize the Connection object before you do the Open as in:
Set con = New ADODB.Connection

And finally you should not only close the Recordset and Connection objects, but also set them to nothing, before exiting the function.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17090249
>>The ReFill method is different than the standard Refresh method, which just forces a Repaint event.<<
I strongly urge you to do some reading up on this.  To put it mildly you are simply not correct.
0
 
LVL 9

Expert Comment

by:pradapkumar
ID: 17096855
>>The ReFill method is different than the standard Refresh method, which just forces a Repaint event.<<


sorry sir,
I took the above lines from October 2000 MSDN collection.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17099321
>>took the above lines from October 2000 MSDN collection.<<
No problem, the article no doubt is outdated or just plain incorrect.

Here is a link to a reference containing all the DataCombo's Poperties, Methods and Events:
DataCombo Control
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/DBList98/html/vbctldatacombocontrol.asp
0
 
LVL 9

Expert Comment

by:pradapkumar
ID: 17106142
0
 
LVL 9

Expert Comment

by:pradapkumar
ID: 17106150
I am not intended to prove my words. But I am also like to become an expert like you. Please don't mistake me.
0
 
LVL 2

Author Comment

by:Masterofdisaster1020
ID: 17733093
according my comment on 07/11/2006, I was expecting to get the points refunded.
I've got no doubt the experts did there best withe providing me some code, but the solution to my problem was given by a person who has not reacted on my post.
read:
"In the mean time I was looking over the EE site and found this article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;230167&Product=vbb
provided by user "emoreau". "


Thx a lot
MOD
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17756999
PAQed with points refunded (125)

DarthMod
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question