Quote Originally Posted by HowardKaplan View Post
It is possible to run code that is part of a form's module while the form is in Design View or not even open, but the code has to be launched from somewhere else. It's easy to create a demo that shows this. Form1 needs only the following simple code:
Public Sub BigLoop()
Dim J As Long
   Do
      J = J + 1
      If ((J Mod 100) = 0) Then
         Debug.Print J, Me.CurrentView
      End If
      DoEvents
   Loop
End Sub
When this loop runs, it displays ever-increasing numbers in the Immediate window, each number followed by the value of CurrentView. In addition, there needs to be a non-form module with this code:
Sub LoopTest()
   Form_Form1.BigLoop
End Sub
If this LoopTest routine is run directly from the VBA editor, while Form1 is open in Design View, you can see output scrolling through the Immediate window, and each line of output ends with "0" for design mode. If the same experiment is tried while Form1 is open in Form View or is not even open at all, each line ends with "1". The code in Form1 can run without Form1's being open in Form View.

Where this becomes important is if a form has a loop running for which the termination condition cannot happen if the form or its Parent is switched back to Design View, because the termination condition depends on a button press. The loop may continue to run indefinitely, and that can cause problems during development, though perhaps not after deployment. I tried to create a tiny model demonstration of such a circumstance, with Form1 as a subform of another form, but the attempt to fetch the CurrentView property caused a VBA error trap whenever the Parent's view was changed. However, I've seen the code continue to loop without error in a larger project; I'm not sure what accidental subtlety of the larger project I'm missing in the tiny model.
This is exactly what I have been looking for! I have two databases at separate locations but on the same network. They are not split because I have 20 users between the two locations approx 10 per database. They are mainly in the database one at a time inputting maintenance entries etc. I am constantly updating the database multiple times a day so splitting it or creating an "Executable" is not a practical option at this time. I need to know when someone attempts to enter design view because some people discovered they can add existing fields that I have removed. I have a Globals.Logging activity tracker that logs each user by login for every form that they access throughout the database (queries have been converted to forms as well). I need to know who, what, where, and when...

I am currently playing with this code and I am close to what I need but I am missing something. When I attach to my activity log Global.Logging "Design View" I get the loop of the text "Design View" in place of the form name like I'd like but it repeats wheather its in Form View or Design View and it does sometime prevent me from re-accessing the form I am testing on.
I added this to the On Load:

Dim J As Long
Do
J = J + 1
If ((J Mod 100) = 0) Then
Globals.Logging "Design View"
End If
DoEvents
Loop

I know this is an older thread but any assistance you can provide would be greatly appreciated! I finally see a light at the end of the tunnel! I have been researching this for a long time before finding this piece of treasure...
Please, I hope someone is still out there that can lend a hand.