Predmet:Re: Pretraga
evo ti kod za to tvoje trenutno stanje.
PreuzmiIzvorni kôd (Visual Basic):Private Sub Command17_Click()
Dim SQL As String, Kriterij As String, RecordSource As String, Uslov As String
Dim Brojac As Integer
Dim Db As dao.Database
Dim Rs As dao.Recordset
Set Db = CurrentDb()
Kriterij = ""
If Format$(Me.Text18) <> "" Then
SQL = "SELECT * FROM grad WHERE ime like " & Chr(39) & Me.Text18 & Chr(42) & Chr(39)
Set Rs = Db.OpenRecordset(SQL)
Do While Not Rs.EOF
Uslov = Uslov & "," & Rs.Fields(0)
Rs.MoveNext
Loop
Uslov = Mid(Uslov, 2)
End If
SQL = "SELECT * FROM Imenik"
Dodaj_Kriterij Me.Text11, "(ime & ' ' & prezime)", Kriterij, Brojac, 0
Dodaj_Kriterij Uslov, "ID_grad", Kriterij, Brojac, 1
If Kriterij <> "" Then
Kriterij = " WHERE " & Kriterij
End If
RecordSource = SQL & Kriterij
Me.RecordSource = RecordSource
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Nema podataka"
End If
End Sub
Private Sub Dodaj_Kriterij(VrijednostPolja As Variant, ImePolja As String, Kriterij As String, Brojac As Integer, Tip As Integer)
If VrijednostPolja <> "" Then
If Brojac > 0 Then
Kriterij = Kriterij & " AND "
End If
If Tip = 0 Then
Kriterij = (Kriterij & ImePolja & " Like " & Chr(39) & VrijednostPolja & Chr(42) & Chr(39))
ElseIf Tip = 1 Then
Kriterij = (Kriterij & ImePolja & " IN(" & VrijednostPolja & ")")
End If
Brojac = Brojac + 1
End If
End Sub
Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.