Skip to content
Advertisement

How to check if field value is same as combobox value?

So I am making a SQL query in which value of combobox (cboVU) shoud be same as field in table called Vrsta uredaja in table O klima uredaju. I am making this query in Access 2016.

I am getting this:

enter image description here

 strRowsource2 = "SELECT " & _
                 "  Vlasnik.ID_VU, " & _
                 "  Vlasnik.[Naziv tvrtke], " & _
                 "  Vlasnik.[Ime korisnika], " & _
                 "  Vlasnik.[Prezime korisnika], " & _
                 "  Vlasnik.[Adresa korisnika], " & _
                 "  Vlasnik.Telefon, " & _
                 "  Vlasnik.Mail, " & _
                 "  [O klima uredaju].[Vrsta uredaja], " & _
                 "  Narudzba.Datum " & _
                 "FROM Vlasnik " & _
                 "INNER JOIN ([O klima uredaju] " & _
                 "INNER JOIN Narudzba " & _
                 "  ON [O klima uredaju].ID_KU = Narudzba.ID_KU) " & _
                 "  ON Vlasnik.ID_VU = Narudzba.ID_VU WHERE ([O klima uredaju].[Vrsta uredaja] = " & cboVU & ")) "
       List1.RowSource = strRowsource2

Tables and relations: enter image description here

Advertisement

Answer

To continue on @Nathan_Sav’s comment:

    Private Sub cboVU_Change()

    strRowsource2 = "SELECT " & _
                     "  Vlasnik.ID_VU, " & _
                     "  Vlasnik.[Naziv tvrtke], " & _
                     "  Vlasnik.[Ime korisnika], " & _
                     "  Vlasnik.[Prezime korisnika], " & _
                     "  Vlasnik.[Adresa korisnika], " & _
                     "  Vlasnik.Telefon, " & _
                     "  Vlasnik.Mail, " & _
                     "  [O klima uredaju].[Vrsta uredaja], " & _
                     "  Narudzba.Datum " & _
                     "FROM Vlasnik " & _
                     "INNER JOIN ([O klima uredaju] " & _
                     "INNER JOIN Narudzba " & _
                     "  ON [O klima uredaju].ID_KU = Narudzba.ID_KU) " & _
                     "  ON Vlasnik.ID_VU = Narudzba.ID_VU " & _
                     "WHERE [O klima uredaju].[Vrsta uredaja] = " & "'" & cboVU.Value & "'" & " "

Debug.Print strRowsource2
Debug.Print List1.RowSource

List1.RowSource = strRowsource2

End Sub
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement