?
Solved

Lable value from 2 ComboBox

Posted on 2009-12-19
7
Medium Priority
?
241 Views
Last Modified: 2012-05-08
Hello again,

I Have a problem with the code. The code is suppose to put the company mane and the adress depending on the value from Combo1 and Combo2, by clicking on a botton.

With the code bellow, it allways put the same company name and adress, no matter what value is in the combo1 and combo2, and i dont know why. Actually, it put the last company name and adress from the last line in the access dbase.

Could you help me agin please?

Thanks again.
Private Sub cmdActiver_Click()
Dim sSQL1 As String
 Dim oRST1 As adodb.Recordset
  Set oRST1 = New adodb.Recordset
    Dim oConnect1 As adodb.Connection
  Set oConnect1 = New adodb.Connection

sSQL1 = "SELECT Nom, Prénom, Compagnie, Adresse  FROM [Table2]"
oConnect1.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source= C:\Base.accdb;"
'Change THIS LINE
'oRST.Open "select * from studentdetails", oConnect
'to THIS
oRST1.Open sSQL1, oConnect1

If Combo1 > "" Then
    Set lblLabel2.DataSource = oRST1
    lblLabel2.DataField = "Compagnie" 'The name of the field you want to follow in the LABEL
    
    Set Label1.DataSource = oRST1
    Label1.DataField = "Adresse"
    End If
    
End Sub

Open in new window

0
Comment
Question by:Wilder1626
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 26088526
Apart from testing to see if the value of Combo1's default property is greater than a zero-length string, you don't do anything with it.
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 26088656
So the code is not good then, at lease to do what i want to do?
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 26088819
You would have to do something with the values of the combo boxes. What is the data in their lists?
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 11

Author Comment

by:Wilder1626
ID: 26088846
In Combo1, we have ("Nom") = Family name.

In Combo2, I have the ("Prénom") = Name that goes with the family name.

ex:

Nom               Prénom                Compagnie                     Adresse
Browning       John                      Kraft                               11 holme street
Browning       Carl                       Bell                                 120 Pearl street
Bolton            Shean                   Videotron                        2398 Carlton street


So when i select let say Browning in Combo1, in combo2, i see 2 names: John and Carl.

If i select Carl in Combo2, then it will put the "Compagnie" Bell in lblLabel2, and it will put the "Adresse" 120 Pearl street in Label1.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 26088978
If you already have the combos loaded, then you can use a Filter on the recordset
'...
    If Combo1.Value > "" Then
        oRST1.Filter = "Nom = '" & Combo1.Value & "' AND Prénom = '" & Combo2.Value & "'"
        Set lblLabel2.DataSource = oRST1
        lblLabel2.DataField = "Compagnie" 'The name of the field you want to follow in the LABEL
        Set Label1.DataSource = oRST1
        Label1.DataField = "Adresse"
    End If

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 26088995
I just change 2 things and now, it work.

I change that:
oRST1.Filter = "Nom = '" & Combo1.Value & "' AND Prénom = '" & Combo2.Value & "'"

With that:
oRST1.Filter = "Nom = '" & Combo1.Text & "' AND Prénom = '" & Combo2.Text & "'"

Thanks a lot, again.
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 31668154
Thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Suggested Courses

862 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