Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

datacombo listview (change) according predefined choice

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
Masterofdisaster1020
Asked:
Masterofdisaster1020
  • 9
  • 6
  • 4
  • +1
1 Solution
 
Anthony PerkinsCommented:
Post your code and we can probalby point out the problem.  

P.S. There is no need to use the ADO data control.
0
 
Masterofdisaster1020Author Commented:
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
 
Anthony PerkinsCommented:
I am sorry, but I don't use the DataCombo, let alone the ADO Data Control.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
pradapkumarCommented:
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
 
Anthony PerkinsCommented:
pradapkumar,

I suspect you mean:
DataCombo1.Refresh
0
 
pradapkumarCommented:
The ReFill method is different than the standard Refresh method, which just forces a Repaint event.
0
 
pradapkumarCommented:
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
 
pradapkumarCommented:
so you can use any one of the above which will work for you.
0
 
Masterofdisaster1020Author Commented:
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
 
pradapkumarCommented:
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
 
pradapkumarCommented:
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
 
Anthony PerkinsCommented:
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
 
Anthony PerkinsCommented:
>>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
 
pradapkumarCommented:
>>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
 
Anthony PerkinsCommented:
>>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
 
pradapkumarCommented:
0
 
pradapkumarCommented:
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
 
Masterofdisaster1020Author Commented:
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
 
DarthModCommented:
PAQed with points refunded (125)

DarthMod
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 6
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now