diesel_medic
New member
- Local time
- Today, 23:29
- Joined
- Sep 29, 2007
- Messages
- 6
Hi,
I've been trying to get the sub bellow, without much suceess.
Private Sub cmdSearchDate_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim StartDate As Date
Dim EndDate As Date
If IsNothing(txtStartDate) Or IsNothing(txtEndDate) Then
MsgBox "You must input a start and end date", vbOKOnly, "Katymin's Korner Accounts Administraion System"
txtStartDate.SetFocus
Exit Sub
End If
StartDate = txtStartDate
EndDate = txtEndDate
strSQL = "SELECT Sum([tblTransactionsSummary].ExVATPrice) AS [SalesTotal]"
strSQL = strSQL + " FROM [tblTransactionsSummary]"
strSQL = strSQL + " WHERE ((([tblTransactionsSummary].SaleDate)"
strSQL = strSQL + " Between [StartDate] And [EndDate]"
strSQL = strSQL + " And (([tblTransactionsSummary].Confirmed)=True))"
Set db = DBEngine(0)(0)
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
With rst
.MoveFirst
txtTotalSales = ![SalesTotal]
End With
Set rst = Nothing
End Sub
The SQL statement works when I put it the Access Query Builder and I get the desired results, but when I try it in VBA, I keep getting a runtime error 3061. Any help would be appreciated.
I've been trying to get the sub bellow, without much suceess.
Private Sub cmdSearchDate_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim StartDate As Date
Dim EndDate As Date
If IsNothing(txtStartDate) Or IsNothing(txtEndDate) Then
MsgBox "You must input a start and end date", vbOKOnly, "Katymin's Korner Accounts Administraion System"
txtStartDate.SetFocus
Exit Sub
End If
StartDate = txtStartDate
EndDate = txtEndDate
strSQL = "SELECT Sum([tblTransactionsSummary].ExVATPrice) AS [SalesTotal]"
strSQL = strSQL + " FROM [tblTransactionsSummary]"
strSQL = strSQL + " WHERE ((([tblTransactionsSummary].SaleDate)"
strSQL = strSQL + " Between [StartDate] And [EndDate]"
strSQL = strSQL + " And (([tblTransactionsSummary].Confirmed)=True))"
Set db = DBEngine(0)(0)
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
With rst
.MoveFirst
txtTotalSales = ![SalesTotal]
End With
Set rst = Nothing
End Sub
The SQL statement works when I put it the Access Query Builder and I get the desired results, but when I try it in VBA, I keep getting a runtime error 3061. Any help would be appreciated.