Hello All,
Back at it with a little syntax situation. I've been trying to prevent folks from closing the database by simply clicking the "X" in order to avoid any issues with events and VBA coding.
I have a form that loads hidden whenever they log in and have place this code (see below) to trigger on the Unload Event. Initially, I wanted it to cancel the unload process, [ cancel = true] but I wanted to give a message that will tell folks whats going on. It will do nothing, which is fine, but knowing my users theres going to be a bit of chaos. So, I thought to add a message whenever the event happens. and Of course it works but It also gives me the message when I close the database correctly (using the button on the main form).
I've gotten the code to work correctly, to an extent: Click the X, get prompt, do nothing. Use close button, get prompt, close database correctly.
I want it to avoid the prompt if the close button has been used/pressed but for some reason it is NOT catching that button click. it will give me the prompt and then close the database. Ive tried using the EXIT sub and the call Close before the else.
Please take a look, any suggestions or corrections are much appreciated. THank you.
Back at it with a little syntax situation. I've been trying to prevent folks from closing the database by simply clicking the "X" in order to avoid any issues with events and VBA coding.
I have a form that loads hidden whenever they log in and have place this code (see below) to trigger on the Unload Event. Initially, I wanted it to cancel the unload process, [ cancel = true] but I wanted to give a message that will tell folks whats going on. It will do nothing, which is fine, but knowing my users theres going to be a bit of chaos. So, I thought to add a message whenever the event happens. and Of course it works but It also gives me the message when I close the database correctly (using the button on the main form).
I've gotten the code to work correctly, to an extent: Click the X, get prompt, do nothing. Use close button, get prompt, close database correctly.
I want it to avoid the prompt if the close button has been used/pressed but for some reason it is NOT catching that button click. it will give me the prompt and then close the database. Ive tried using the EXIT sub and the call Close before the else.
Please take a look, any suggestions or corrections are much appreciated. THank you.
Private Sub Form_Unload(Cancel As Integer) If CurrentUser() <> "whoever" And DCount("*", "tblCurrentlyLoggedIn", "empCurrentlyLoggedIn=" & Chr(34) & CurrentUser() & Chr(34)) > 0 And DCount("*", "tblCurrentlyLoggedIn", "empEnviron=" & Chr(34) & Environ("computername") & Chr(34)) > 0 And CurrentProject.AllForms("EAA-Database-Payroll").IsLoaded = True And [Forms]![EAA-Database-Payroll].[Command195].OnClick = True Then Exit Sub Else Cancel = True MsgBox CurrentUser() & _ vbCrLf & " " & _ vbCrLf & "Please close the database using the Log-Off button.", vbExclamation, "Attention." End If End Sub |