D
Dennis Snelgrove
This is going to be lengthy.
I've got an event-log database. The main screen has the records showing
events as they occur. Much of our work is in the concept of "First Event A
occurs, then at some point a little later Event B occurs, then later Event
C, and then later again Event D." I found it useful and much more efficient
to put a shortcut button on the subform where if the button isn't blank,
clicking it will auto enter the next Event along with a number of related
information from that specific record. I put a user-defined calculation into
the subform's Recordsource wherein I pass the current record's Primary key
(an autonumber) and it looks to see if any subsequent Events have occurred.
If they have, then this record's button is blanked out since the following
Event has already occurred. If the following Event hasn't occurred, the
button's caption is set appropriately.
Now for the part I need clarified. Below is the user-defined function. Up to
now, the query I've run have taken at most 3-5 seconds, which for our
purposes is acceptable. Now I'm building an almost identical query where I'm
applying criteria to this function. The run-time for this query has gone
from 5 seconds to about 2 minutes. I removed the criteria for just this
calculated field, and the runtime dropped back to 5 seconds. I've also tried
removing just this one criterion and then making a new query which uses this
query as the sole source, and applying the criteria in there. No
difference - it still went back up to 2 minutes again. I figure that the
reason for the large delay is the fact that the PC is doing large amounts of
creating Recordsets and doing a lot of DCounts, as per the u.d.f. What I don
't' understand is why the runtime is becoming so large when criteria is put
against that calculation, versus when it's just another field.
Anyone willing to discuss this with me, or even better yet, make a
suggestion or offer insights, I'd be most grateful.
Thanks.
----------------------------------------------------------------------------
---
Public Function ActionLabel(CallID As Long) As String
' This function will take the Primary Key value for an entry, and return the
' proper caption for the "Make In or Out entry" textbox on the Call-out
detail
' subform
'
' If the "Make In entry" textbox is clicked, the program will auto-create a
' new entry for that person with the current time, the Action field will be
' set to "In" and all other fields copied forward from the "Confirmed" entry
'
' If the "Make Out entry" textbox is clicked, the program will auto-create a
' new entry for that person with the current time, the Action field will be
' set to "Out" and all other fields copied forward from the "In" entry
'
' The flow of the call-out program is as follows:
' - call a person to come in
' - if that person confirms, put "Confirmed" in the Comments field. This
' will cause the "Make In entry" label to appear in that entry
' - when that employee books in, the Dispatcher simply clicks the "Make
' In entry" and a new entry is auto-created for that employee with
' an Action of "In" and the current time. The "Make In entry" button
' on the confirmation entry will disappear because the "In" now entry
exists
' - when that employee books out, the Dispatcher simply clicks the "Make
Out
' entry" button and a new entry is auto-created for that employee with
' an Action of "Out" and the current time. The "Make Out entry" button
' will disappear because the "Out" entry now exists
Dim rs As DAO.Recordset
Dim strSQLCondition As String
Dim strSQLCondition1 As String
' Get all fields for the current entry
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblCallOutDetail WHERE
[CallID]=" & CallID)
' The first condition is used to check if there are any "In" entries for
this employee
' that fall after this entry. If not, then the ActionLabel is "Make In
Entry"
strSQLCondition = "(([Action]='In') And ([CallTime]>=#" & _
Nz(rs("CallTime"), rs("TimeEntered")) & _
"#) And ([NamesID]=" & _
rs("NamesID") & "))"
' The second condition is used to check if there are any "Out" entries for
this employee
' that fall after this entry. If not, then the ActionLabel is "Make Out
Entry"
strSQLCondition1 = "(([Action]='Out') And ([CallTime]>=#" & _
Nz(rs("CallTime"), rs("TimeEntered")) & "#) And
([NamesID]=" & _
rs("NamesID") & "))"
' Give a "Make Out entry" on one of two conditions - Action is "In" and:
' - the CallTime is not Null
' - the CallTime is Null and the Comments is "Shift Driver"
If rs("Action") = "In" Then
If (Not IsNull(rs("CallTime"))) Or ((IsNull(rs("CallTime")) _
And (rs("Comments") = "Shift Driver"))) Then
If DCount("*", "tblCallOutDetail", strSQLCondition1) = 0 Then
ActionLabel = "Make Out entry"
End If
End If
Else
If rs("Comments") = "Confirmed" Then
If DCount("*", "tblCallOutDetail", strSQLCondition) = 0 Then
ActionLabel = "Make In entry"
Else
ActionLabel = ""
End If
Else
ActionLabel = ""
End If
End If
Set rs = Nothing
End Function
I've got an event-log database. The main screen has the records showing
events as they occur. Much of our work is in the concept of "First Event A
occurs, then at some point a little later Event B occurs, then later Event
C, and then later again Event D." I found it useful and much more efficient
to put a shortcut button on the subform where if the button isn't blank,
clicking it will auto enter the next Event along with a number of related
information from that specific record. I put a user-defined calculation into
the subform's Recordsource wherein I pass the current record's Primary key
(an autonumber) and it looks to see if any subsequent Events have occurred.
If they have, then this record's button is blanked out since the following
Event has already occurred. If the following Event hasn't occurred, the
button's caption is set appropriately.
Now for the part I need clarified. Below is the user-defined function. Up to
now, the query I've run have taken at most 3-5 seconds, which for our
purposes is acceptable. Now I'm building an almost identical query where I'm
applying criteria to this function. The run-time for this query has gone
from 5 seconds to about 2 minutes. I removed the criteria for just this
calculated field, and the runtime dropped back to 5 seconds. I've also tried
removing just this one criterion and then making a new query which uses this
query as the sole source, and applying the criteria in there. No
difference - it still went back up to 2 minutes again. I figure that the
reason for the large delay is the fact that the PC is doing large amounts of
creating Recordsets and doing a lot of DCounts, as per the u.d.f. What I don
't' understand is why the runtime is becoming so large when criteria is put
against that calculation, versus when it's just another field.
Anyone willing to discuss this with me, or even better yet, make a
suggestion or offer insights, I'd be most grateful.
Thanks.
----------------------------------------------------------------------------
---
Public Function ActionLabel(CallID As Long) As String
' This function will take the Primary Key value for an entry, and return the
' proper caption for the "Make In or Out entry" textbox on the Call-out
detail
' subform
'
' If the "Make In entry" textbox is clicked, the program will auto-create a
' new entry for that person with the current time, the Action field will be
' set to "In" and all other fields copied forward from the "Confirmed" entry
'
' If the "Make Out entry" textbox is clicked, the program will auto-create a
' new entry for that person with the current time, the Action field will be
' set to "Out" and all other fields copied forward from the "In" entry
'
' The flow of the call-out program is as follows:
' - call a person to come in
' - if that person confirms, put "Confirmed" in the Comments field. This
' will cause the "Make In entry" label to appear in that entry
' - when that employee books in, the Dispatcher simply clicks the "Make
' In entry" and a new entry is auto-created for that employee with
' an Action of "In" and the current time. The "Make In entry" button
' on the confirmation entry will disappear because the "In" now entry
exists
' - when that employee books out, the Dispatcher simply clicks the "Make
Out
' entry" button and a new entry is auto-created for that employee with
' an Action of "Out" and the current time. The "Make Out entry" button
' will disappear because the "Out" entry now exists
Dim rs As DAO.Recordset
Dim strSQLCondition As String
Dim strSQLCondition1 As String
' Get all fields for the current entry
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblCallOutDetail WHERE
[CallID]=" & CallID)
' The first condition is used to check if there are any "In" entries for
this employee
' that fall after this entry. If not, then the ActionLabel is "Make In
Entry"
strSQLCondition = "(([Action]='In') And ([CallTime]>=#" & _
Nz(rs("CallTime"), rs("TimeEntered")) & _
"#) And ([NamesID]=" & _
rs("NamesID") & "))"
' The second condition is used to check if there are any "Out" entries for
this employee
' that fall after this entry. If not, then the ActionLabel is "Make Out
Entry"
strSQLCondition1 = "(([Action]='Out') And ([CallTime]>=#" & _
Nz(rs("CallTime"), rs("TimeEntered")) & "#) And
([NamesID]=" & _
rs("NamesID") & "))"
' Give a "Make Out entry" on one of two conditions - Action is "In" and:
' - the CallTime is not Null
' - the CallTime is Null and the Comments is "Shift Driver"
If rs("Action") = "In" Then
If (Not IsNull(rs("CallTime"))) Or ((IsNull(rs("CallTime")) _
And (rs("Comments") = "Shift Driver"))) Then
If DCount("*", "tblCallOutDetail", strSQLCondition1) = 0 Then
ActionLabel = "Make Out entry"
End If
End If
Else
If rs("Comments") = "Confirmed" Then
If DCount("*", "tblCallOutDetail", strSQLCondition) = 0 Then
ActionLabel = "Make In entry"
Else
ActionLabel = ""
End If
Else
ActionLabel = ""
End If
End If
Set rs = Nothing
End Function