Prikazi cijelu temu 16.05.2012 13:25
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Lokacija:Tuzla


Predmet:Re: Queries to VBA
PreuzmiIzvorni kôd (Visual Basic):
  1. Function QueryP()
  2. Dim Db As Database
  3. Dim Rs As Recordset
  4. Dim SQL As String
  5. Dim Datum(1 To 2) As String
  6. Dim Magacin As Integer
  7.  
  8.  
  9. Set Db = CurrentDb()
  10. Magacin = Forms![frmPregled_Kasa_Restoran]![cboMagacin]
  11. Datum(1) = [Forms]![frmPregled_Kasa_Restoran]![txtDataOD]
  12. Datum(1) = DatumSQL(Datum(1))
  13. Datum(2) = [Forms]![frmPregled_Kasa_Restoran]![txtDataDO]
  14. Datum(2) = DatumSQL(Datum(2))
  15. SQL = "SELECT Stavka, Sum(Kolicina) AS Suma, Procent,Ed_Cena " _
  16.     & "FROM tblSmetki " _
  17.     & "INNER JOIN tblSmetki_Stavki ON tblSmetki.ID_Smetka = tblSmetki_Stavki.Smetka_Br " _
  18.     & "WHERE Data Between " & Datum(1) & " AND " & Datum(2) & "AND Magacin=" & Magacin _
  19.     & " GROUP BY Stavka, Procent, Ed_Cena " _
  20.     & "ORDER BY Sum(Kolicina) DESC;"
  21. Set Rs = Db.OpenRecordset(SQL)
  22. While Not Rs.EOF
  23.   MsgBox Rs.Fields(1)
  24.   Rs.MoveNext
  25. Wend
  26. End Function
  27.  
  28.  
  29. Function DatumSQL(Datum As String)
  30. Dim DatumS As String
  31.  
  32. DatumS = Format(Datum, "mm-dd-yyyy hh:nn:ss")
  33. DatumSQL = "#" & DatumS & "#"
  34. End Function

Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.