Solved

datacombo listview (change) according predefined choice

Posted on 2006-07-08
21
255 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now