• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Lable value from 2 ComboBox

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
Wilder1626
Asked:
Wilder1626
  • 4
  • 3
1 Solution
 
GrahamSkanRetiredCommented:
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
 
Wilder1626Author Commented:
So the code is not good then, at lease to do what i want to do?
0
 
GrahamSkanRetiredCommented:
You would have to do something with the values of the combo boxes. What is the data in their lists?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Wilder1626Author Commented:
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
 
GrahamSkanRetiredCommented:
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
 
Wilder1626Author Commented:
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
 
Wilder1626Author Commented:
Thanks
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

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now