|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Feb 2001
Città: Reggio Emilia
Messaggi: 230
|
[VBA] Query con parametri
Codice:
Set dbs = CurrentDb
Set FidoResiduo = dbs.OpenRecordset("SELECT DISTINCTROW Sum(TabellaOperazioni.[TOTALE SEND]) AS [TOTALE SEND]," _
& "Sum(TabellaOperazioni.[IMPORTO RECEIVE]) AS [IMPORTO RECEIVE]," _
& "Sum(TabellaOperazioni.[TOTALE QUICK]) AS [TOTALE QUICK], Sum(TabellaOperazioni.BONIFICO) AS BONIFICO," _
& "Sum([TabellaOperazioni].[TOTALE SEND])-NZ(Sum([TabellaOperazioni].[IMPORTO RECEIVE]))-NZ(Sum([TabellaOperazioni].[BONIFICO]))+NZ(Sum([TabellaOperazioni].[TOTALE QUICK])) AS [DA PAGARE]," _
& "Round(DLookUp('[fido settimanale]','[tblFido]')+nz(Sum([TabellaOperazioni].[BONIFICO]))-nz(Sum([TabellaOperazioni].[TOTALE SEND]))+nz(Sum([TabellaOperazioni].[IMPORTO RECEIVE]))-nz(Sum([TabellaOperazioni].[TOTALE QUICK])),2) AS [FIDO RESIDUO]" _
& "FROM TabellaOperazioni WHERE(((TabellaOperazioni.DATA) Between Date() And Date()-5))")
Io vorrei sostituire date()-5 con una variabile ma non sò come si fa. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2002
Città: Morio Cho
Messaggi: 2595
|
È access, sì?
Bé, non lo conosco bene, ma da quello che vedo il metodo OpenRecordset prende come argomento una stringa che contiene un'istruzione SQL, giusto? Puoi comporre l'istruzione come vuoi. Ad esempio: Codice:
stringaSQL = "select " & nomeCampo & " from tabella" Set FidoResiduo = dbs.OpenRecordset(stringaSQL) Analogamente per la data. Però devi fare attenzione al formato della data. Access se non sbaglio accetta le date nel formato seguente: Codice:
#5/15/2008# Fa' qualche tentativo per essere sicuro che la data venga passata correttamente. Oppure, per non porti neanche il problema, rendi dinamico solo lo scarto (cioè "5" nell'espressione "Date() - 5"), così non devi preoccuparti del formato della data.
__________________
Sono GULDO, non Guido! Cioè, certo che guido... Bé, insomma, avete capito ![]() Linux 2.6.26|Debian|Debian@Hwupgrade|Debian Clan|Solo Puffin ti darà forza e grinta a volontà! NERD rank 62|Milla Jovovich|大事な物はいつも形の無い物だけ Sito e Forum sul Giappone|La mia libreria su aNobii |
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Feb 2001
Città: Reggio Emilia
Messaggi: 230
|
Codice:
Private Sub Comando517_Click()
Dim inizio, fine
Dim Criteri As String
If Weekday(Date) = 1 Then 'Domenica
inizio = Date - 6
End If
If Weekday(Date) = 2 Then 'Lunedi
inizio = Date
End If
If Weekday(Date) = 3 Then 'Martedi
inizio = Date - 1
End If
If Weekday(Date) = 4 Then 'Mercoledi
inizio = Date - 2
End If
If Weekday(Date) = 5 Then 'Giovedi
inizio = Date - 3
End If
If Weekday(Date) = 6 Then 'Venerdi
inizio = Date - 4
End If
If Weekday(Date) = 7 Then 'Sabato
inizio = Date - 5
End If
Criteri = "'(TabellaOperazioni.DATA) between " & Date & " And " & inizio & "'"
Set dbs = CurrentDb
Set FidoResiduo = dbs.OpenRecordset("SELECT DISTINCTROW Sum(TabellaOperazioni.[TOTALE SEND]) AS [TOTALE SEND]," _
& "Sum(TabellaOperazioni.[IMPORTO RECEIVE]) AS [IMPORTO RECEIVE]," _
& "Sum(TabellaOperazioni.[TOTALE QUICK]) AS [TOTALE QUICK], Sum(TabellaOperazioni.BONIFICO) AS BONIFICO," _
& "Sum([TabellaOperazioni].[TOTALE SEND])-NZ(Sum([TabellaOperazioni].[IMPORTO RECEIVE]))-NZ(Sum([TabellaOperazioni].[BONIFICO]))+NZ(Sum([TabellaOperazioni].[TOTALE QUICK])) AS [DA PAGARE]," _
& "Round(DLookUp('[fido settimanale]','[tblFido]')+nz(Sum([TabellaOperazioni].[BONIFICO]))-nz(Sum([TabellaOperazioni].[TOTALE SEND]))+nz(Sum([TabellaOperazioni].[IMPORTO RECEIVE]))-nz(Sum([TabellaOperazioni].[TOTALE QUICK])),2) AS [FIDO RESIDUO]" _
& "FROM TabellaOperazioni WHERE(((TabellaOperazioni.DATA) Between Date() And Date()-5))")
MsgBox FidoResiduo("FIDO RESIDUO")
End Sub
|
|
|
|
|
|
#4 | |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Quote:
Così, al volo : Codice:
& "FROM TabellaOperazioni WHERE(((TabellaOperazioni.DATA) Between Date() And " & CDate(inizio) & "))" ) |
|
|
|
|
|
|
#5 |
|
Member
Iscritto dal: Feb 2001
Città: Reggio Emilia
Messaggi: 230
|
Codice:
Function CalcolaFidoResiduo()
Dim Differenza
If Weekday(Date) = 1 Then 'Domenica
Differenza = -6
End If
If Weekday(Date) = 2 Then 'Lunedi
Differenza = -0
End If
If Weekday(Date) = 3 Then 'Martedi
Differenza = -1
End If
If Weekday(Date) = 4 Then 'Mercoledi
Differenza = -2
End If
If Weekday(Date) = 5 Then 'Giovedi
Differenza = -3
End If
If Weekday(Date) = 6 Then 'Venerdi
Differenza = -4
End If
If Weekday(Date) = 7 Then 'Sabato
Differenza = -5
End If
Set dbs = CurrentDb
Set FidoResiduo = dbs.OpenRecordset("SELECT DISTINCTROW Sum(TabellaOperazioni.[TOTALE SEND]) AS [TOTALE SEND]," _
& "Sum(TabellaOperazioni.[IMPORTO RECEIVE]) AS [IMPORTO RECEIVE]," _
& "Sum(TabellaOperazioni.[TOTALE QUICK]) AS [TOTALE QUICK], Sum(TabellaOperazioni.BONIFICO) AS BONIFICO," _
& "Sum([TabellaOperazioni].[TOTALE SEND])-NZ(Sum([TabellaOperazioni].[IMPORTO RECEIVE]))-NZ(Sum([TabellaOperazioni].[BONIFICO]))+NZ(Sum([TabellaOperazioni].[TOTALE QUICK])) AS [DA PAGARE]," _
& "Round(DLookUp('[fido settimanale]','[tblFido]')+nz(Sum([TabellaOperazioni].[BONIFICO]))-nz(Sum([TabellaOperazioni].[TOTALE SEND]))+nz(Sum([TabellaOperazioni].[IMPORTO RECEIVE]))-nz(Sum([TabellaOperazioni].[TOTALE QUICK])),2) AS [FIDO RESIDUO]" _
& "FROM TabellaOperazioni WHERE (TabellaOperazioni.DATA) between Date() And " & "Date()" & Differenza)
End Function
Grazie mille |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 05:05.





















