UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Overhead For Opening Recordset, Access 2016    
 
   
wheeledgoat
post Aug 28 2019, 10:08 AM
Post#1



Posts: 68
Joined: 18-December 18



How much overhead/cpu cycles are consumed opening the recordset? Would it be worth including an IF statement to check if either chkSound or chkPopup are ticked before opening the recordset?


CODE
Private Sub Form_Timer()
Me.Requery
Me.TimerInterval = 60000 'reset timer to prevent double alerts if sub is called via refresh button

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM qryPharmacy")

If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst
    Do Until rs.EOF = True
        If rs!RTMWaitSec < 60 Then
            On Error Resume Next
            If chkSound.Value = True Then API_PlaySound "new", 1
            If chkPopup.Value = True Then AppActivate "Compass - Pharmacy Board"
            Exit Sub
        End If
        rs.MoveNext
    Loop
End If

ExitSub:
rs.Close 'Close the recordset
Set rs = Nothing 'Clean up

End Sub

--------------------
"If you don't make mistakes, you're not working on hard enough problems." -Frank Wilczek

"Success is getting what you want. Happiness is wanting what you get." -B.R. Hayden

Virtue is sufficient for happiness, therefore a sage is immune to misfortune.
Go to the top of the page
 
ADezii
post Aug 28 2019, 11:42 AM
Post#2



Posts: 2,689
Joined: 4-February 07
From: USA, Florida, Delray Beach


  1. I am assuming from your question that you are dealing with a very large Recordset?
  2. If this is indeed the case, during the processing of the Recordset, you can release control to the Operating System in order to process any pending Events in the Queue.
  3. I have included a very simple example that simulates the processing of a very large Recordset. At specified intervals (lngCtr Mod 50000 = 0) control is released back to the environment to check any events that need to be processed, such as the clicking of a Check Box.
  4. Code Definition:
    CODE
    Dim lngRecCount As Long
    Dim lngCtr As Long

    DoCmd.Hourglass True

    lngRecCount = 1000000       'Simulate a very large Recordset

    For lngCtr = 1 To lngRecCount
      If lngCtr Mod 50000 = 0 Then DoEvents
        Debug.Print 2 * lngCtr
    Next

    DoCmd.Hourglass False

    MsgBox "done"
  5. Now, there is no need to check the Status of chkSound and chkPopup with the Recordset Loop. Code can exist within the Click() Event of these two Controls, as in:
    CODE
    Private Sub chkSound_Click()
      Me![imgOne].Visible = Me![chkSound].Value
    End Sub

    CODE
    Private Sub chkPopup_Click()
      Me![imgTwo].Visible = Me![chkPopup].Value
    End Sub
  6. Hope this helps.

This post has been edited by ADezii: Aug 28 2019, 12:10 PM
Go to the top of the page
 
projecttoday
post Aug 28 2019, 12:04 PM
Post#3


UtterAccess VIP
Posts: 11,205
Joined: 10-February 04
From: South Charleston, WV


It would be good practice in any case, at the beginning of the code:

CODE
If chkSound.Value = False And chkPopup.Value = False Then Exit Sub

--------------------
Robert Crouser
Go to the top of the page
 
wheeledgoat
post Aug 28 2019, 12:24 PM
Post#4



Posts: 68
Joined: 18-December 18



@ADezii

2,3,4: neato! had no idea that functionality existed. don't think it's necessary for this project, but i'm tucking that into my back pocket. thanks!

5. I'm not sure I follow. I'm not familiar with that approach, but the chkSound and chkPopup are settings that can be toggled on and off by the user - once set to their preference, the user won't touch the checkboxes again (and will usually never check the boxes since normal operation is set by default). Depending on their checked state, the timer code plays a sound or popup the window if new records are found on the record check. Am I missing something?


--------------------
"If you don't make mistakes, you're not working on hard enough problems." -Frank Wilczek

"Success is getting what you want. Happiness is wanting what you get." -B.R. Hayden

Virtue is sufficient for happiness, therefore a sage is immune to misfortune.
Go to the top of the page
 
wheeledgoat
post Aug 28 2019, 12:26 PM
Post#5



Posts: 68
Joined: 18-December 18



@projecttoday

Yes indeed, this is what I was getting at. It does make sense to add that, doesn't it? Thanks, that's all I needed to hear. thumbup.gif

--------------------
"If you don't make mistakes, you're not working on hard enough problems." -Frank Wilczek

"Success is getting what you want. Happiness is wanting what you get." -B.R. Hayden

Virtue is sufficient for happiness, therefore a sage is immune to misfortune.
Go to the top of the page
 
ADezii
post Aug 28 2019, 12:37 PM
Post#6



Posts: 2,689
Joined: 4-February 07
From: USA, Florida, Delray Beach


QUOTE
Am I missing something?

I think that I'm the one who is missing something! iconfused.gif
Go to the top of the page
 
projecttoday
post Aug 28 2019, 12:39 PM
Post#7


UtterAccess VIP
Posts: 11,205
Joined: 10-February 04
From: South Charleston, WV


You're welcome.

--------------------
Robert Crouser
Go to the top of the page
 
wheeledgoat
post Aug 29 2019, 08:36 AM
Post#8



Posts: 68
Joined: 18-December 18



I'm surprised no one admonished me for not closing the recordset! Somehow I only just noticed that (after a new record is found it goes to "Exit Sub" instead of "GoTo ExitSub" where the rs.close is).

Stay frosty out there! hat_tip.gif

--------------------
"If you don't make mistakes, you're not working on hard enough problems." -Frank Wilczek

"Success is getting what you want. Happiness is wanting what you get." -B.R. Hayden

Virtue is sufficient for happiness, therefore a sage is immune to misfortune.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    19th November 2019 - 11:09 AM