Result: Nothing. Access automatically updated
[Forms]![frmUpdate]![txtSaveDate] to Forms!frmUpdate!txtSaveDate
This is driving me crazy!
*************Here is the code:
Private Sub cmdUpdate_Click()
Dim LoopDate As Date
Dim BranchRec As Long
Dim EmployRec As Long
With Forms.frmUpdate
For LoopDate = .txtStartDate To .txtEndDate
.txtSaveDate = LoopDate
BranchRec = RunQuery("DailyBranchStats")
Next LoopDate
End With
End Sub
*************Here is the function:
Function RunQuery(ByVal RunStr As String) As Long
Dim dbs As DAO.Database
Dim prm As DAO.Parameter
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim strSQL As String
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs(RunStr)
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
qdf.Execute dbFailOnError
RunQuery = qdf.RecordsAffected
qdf.Close
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
End Function
*************DailyBranchStats
INSERT INTO tblBranchStats ( DateRec, CallTime_0715, CallTime_1523,
CallTime_2307 )
SELECT CDate(Forms!frmUpdate!txtSaveDate) AS DateRec,
(DailyBranchStats0715.TotalTalkTime/DailyBranchStats0715.TotalOnTime) AS
CallTime0715,
(DailyBranchStats1523.TotalTalkTime/DailyBranchStats1523.TotalOnTime) AS
CallTime1523,
(DailyBranchStats2307.TotalTalkTime/DailyBranchStats2307.TotalOnTime) AS
CallTime2307
FROM DailyBranchStats0715, DailyBranchStats1523, DailyBranchStats2307;
*************Here are the subqueries.. maybe that will help!
SELECT Sum(mOpInterval.SecTalkTime+mOpInterval.CheckTalkTime) AS
TotalTalkTime, Sum(mOpInterval.OnTime) AS TotalOnTime
FROM mOpInterval IN 'C:\Shared\In Progress\MDRetrieve\MDR.mdb'
WHERE (((mOpInterval.Timestamp)>=((CDate(Forms!frmUpdate!txtSaveDate & "
7:00a")-1)*1440) And
(mOpInterval.Timestamp)<=((CDate(Forms!frmUpdate!txtSaveDate & "
2:59p")+1)*1440)));
SELECT SUM(mOpInterval.SecTalkTime+mOpInterval.CheckTalkTime) AS
TotalTalkTime, SUM(mOpInterval.OnTime) AS TotalOnTime
FROM mOpInterval IN 'C:\Shared\In Progress\MDRetrieve\MDR.mdb'
WHERE (((mOpInterval.Timestamp)>=((CDate(Forms!frmUpdate!txtSaveDate & "
3:00p")-1)*1440) And
(mOpInterval.Timestamp)<=((CDate(Forms!frmUpdate!txtSaveDate & "
10:59p")+1)*1440)));
SELECT SUM(mOpInterval.SecTalkTime+mOpInterval.CheckTalkTime) AS
TotalTalkTime, SUM(mOpInterval.OnTime) AS TotalOnTime
FROM mOpInterval IN 'C:\Shared\In Progress\MDRetrieve\MDR.mdb'
WHERE (((mOpInterval.Timestamp)>=((CDate(Forms!frmUpdate!txtSaveDate & "
11:00p")-1)*1440) And
(mOpInterval.Timestamp)<=((CDate((Forms!frmUpdate!txtSaveDate+1) & "
6:59a")+1)*1440)));
Ken Snell said:
Change
forms.frmUpdate.txtSaveDate
to
[Forms]![frmUpdate]![txtSaveDate]
--
Ken Snell
<MS ACCESS MVP>
I have used the code snippet below creating a function which will be used
to
run any query that is passed to it and returning the number of records
affected. Now I know the query is okay as it runs on it's own but when
called through the snippet you provided it gives me a runtime error 3464
(data type mismatch) on the qdf.execute line.
So here is the saved query:
INSERT INTO tblBranchStats ( DateRec, CallTime_0715, CallTime_1523,
CallTime_2307 )
SELECT CDate(forms.frmUpdate.txtSaveDate) AS DateRec,