Predmet:Re: Queries to VBA
PreuzmiIzvorni kôd (Visual Basic):Function QueryP()
Dim Db As Database
Dim Rs As Recordset
Dim SQL As String
Dim Datum(1 To 2) As String
Dim Magacin As Integer
Set Db = CurrentDb()
Magacin = Forms![frmPregled_Kasa_Restoran]![cboMagacin]
Datum(1) = [Forms]![frmPregled_Kasa_Restoran]![txtDataOD]
Datum(1) = DatumSQL(Datum(1))
Datum(2) = [Forms]![frmPregled_Kasa_Restoran]![txtDataDO]
Datum(2) = DatumSQL(Datum(2))
SQL = "SELECT Stavka, Sum(Kolicina) AS Suma, Procent,Ed_Cena " _
& "FROM tblSmetki " _
& "INNER JOIN tblSmetki_Stavki ON tblSmetki.ID_Smetka = tblSmetki_Stavki.Smetka_Br " _
& "WHERE Data Between " & Datum(1) & " AND " & Datum(2) & "AND Magacin=" & Magacin _
& " GROUP BY Stavka, Procent, Ed_Cena " _
& "ORDER BY Sum(Kolicina) DESC;"
Set Rs = Db.OpenRecordset(SQL)
While Not Rs.EOF
MsgBox Rs.Fields(1)
Rs.MoveNext
Wend
End Function
Function DatumSQL(Datum As String)
Dim DatumS As String
DatumS = Format(Datum, "mm-dd-yyyy hh:nn:ss")
DatumSQL = "#" & DatumS & "#"
End Function
Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.