DoEvents alternative

MackMan

Registered User.
Local time
Today, 17:28
Joined
Nov 25, 2014
Messages
174
In the BeforeUpdate event of a form field, I'm holding open a messagebox (my own design) with DoEvents as I can't allow it to open in dialog mode.

Code:
If Len(Me.ReminderTitle & vbNullString) > 0 Then
        strLinkCriteria = "[ReminderTitle] = " & "'" & Remtitl & "'"
        [COLOR="YellowGreen"]'checks reminders table for duplicate entries
[/COLOR]        If DCount("ReminderTitle", "tblReminders", strLinkCriteria & " AND USERID = " & TempVars!TempLoginID & " AND reminderID <> " & Me.ReminderID) > 0 Then [COLOR="yellowgreen"]'undoes the duplicate entry and shows message box
[/COLOR]            DoCmd.OpenForm "_frmMessagebox", , , , , , ErrCode & "|" & Remtitl
    
            [B][I]Do While (SysCmd(acSysCmdGetObjectState, acForm, "_frmMessageBox") <> 0)
                DoEvents
            Loop
[/I][/B]          
            Me.ReminderTitle.Undo
            Cancel = True
            
        End If
End If

The only thing with DoEvents is that's it eating processor usage as it's constantly looping until the form being held open has a user response.

Other than DoEvents is there an alternative where I can stop the code running still, yet save the processor useage? As I said I can't allow the form to open in dialog mode (as it doesn't retain it's formsize/border properties etc).
 
The Sleep API is fine if you know how long you want to wait.
Another alternative to using DoEvents that is less processor intensive is dbEngine.Idle.dbRefreshCache. See http://www.mendipdatasystems.co.uk/speed-comparison-tests-3/4594428909

And of course you could just use the code line: Stop
This will do exactly that till you restart the code e.g by clicking F5
 

Users who are viewing this thread

Back
Top Bottom