Test for open popup forms (1 Viewer)

Colman

Registered User.
Local time
Today, 06:58
Joined
Sep 5, 2011
Messages
37
I have created a database that includes my own functionality that allows a user to log into the database. I now want to add a timeout feature that logs the user out after a period of idle. I have it working fine using the timer feature on a hidden form but I have one issue to overcome.

My timeout feature must not run if there are any popup forms open. Is there any way to detect this?

I should say that there are dozens of popup forms available to the user, all are modal.

Many thanks
Colman
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:58
Joined
May 7, 2009
Messages
19,246
Search on this forum isFormLoaded to check if a form is loaded/open. Use this to check at least a pop up form name is open and reset the time out if it does.
 

Colman

Registered User.
Local time
Today, 06:58
Joined
Sep 5, 2011
Messages
37
Thanks for your reply. I feel there are too many popup forms in my database to test each one by name to see if it is loaded/open (if that's what you mean). There are more than 100 of them.

Currently thinking I should ask the database for all loaded/open forms and test each of those to see if any are of a modal or a popup design.

Not sure how to test for that though.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:58
Joined
May 7, 2009
Messages
19,246
copy this code in a Standard Module
this will do the checking for all
open form if there is ATLeast one
pop-up form:

Code:
Public Function IsAnyPopUpOpen() As Boolean
    Dim objForm As AccessObject
    For Each objForm In CurrentProject.AllForms
        If objForm.IsLoaded Then
            If Forms(objForm.Name).CurrentView <> acCurViewDesign Then
                IsAnyPopUpOpen = Forms(objForm.Name).PopUp
                Exit For
            End If
        End If
    Next
End Function


all you need to do is use it in your
timerform:

...
...
If IsAnyPopUpOpen() then
' there is at least one
' pop form open
' reset the timeOut
Else
' continue with timeout
End If
...
...
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 06:58
Joined
Jul 9, 2003
Messages
16,353
This is a good problem you have run in to as it will force you to think about programming differently! In other words it will help you level up! I can say that with Confidence because that is what happened to me...

I feel there are too many popup forms in my database to test each one by name

The first thing you learn is to reduce the number of objects. To my mind, if you've got 100 forms it is very likely that the Forms are not substantially different. I can infer this because it would take a tremendous amount of development time to make 100 separate "different" forms. It is most likely that you had a basic form and required it to do something slightly different, you then made a copy of it and altered it slightly. Again; been there, done that!

The new way of thinking about it I am trying to lead you to, is to consider modifying the form with VBA code. The goal is to have 10 or 20 basic forms. Different functionality is added when the form is opened with VBA.

The other thing to consider, as a different way of thinking about programming in MS Access, is to realised that most things are in a collection. You may well have run across code which is structured something like "For Each Control in Me Controls" you would normally find this particular structure associated with a form. The code traverses the collection of objects within the form, operating on each Object individually, dependent on certain criteria you specify.

You may not be aware however, that there is also a similar collection which contains all your Forms. Once you are aware, you can apply the same logic. Instead of trying to locate an individual form by name, you cycle through the Forms collection then make decisions based on what you find.
 

Colman

Registered User.
Local time
Today, 06:58
Joined
Sep 5, 2011
Messages
37
Thanks for the code arnelgp. I found the function was returning False both with and without a popup open. I think the 'Exit For' command meant that it only ever checked the first loaded form and then stopped. I inserted an extra If, then statement and it works now.

If Forms(objForm.name).PopUp Then
IsAnyPopUpOpen = True
Exit For
Else
IsAnyPopUpOpen = False
End If
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:58
Joined
May 7, 2009
Messages
19,246
Glad you made it work...
 

Colman

Registered User.
Local time
Today, 06:58
Joined
Sep 5, 2011
Messages
37
Hi Uncle Gizmo.

Thanks for your reply and for your wisdom. Levelling up sounds good. I'm in.
 

Solo712

Registered User.
Local time
Today, 01:58
Joined
Oct 19, 2012
Messages
828
I am surprised that you would want to distinguish between popups and non-popup forms. Since you are shutting down the app you can simply shut all open forms and then quit the app.

Code:
Public Sub CloseAllForms()
  Dim i As Integer, intErr As Integer, frm As Form, strForm As String
  On Error GoTo ErrExit
  For i = (Forms.Count - 1) To 0 Step -1
        Set frm = Forms(i)
        strForm = frm.Name
        ' Don't close the form requesting the shutdown (this is optional)
        If Not (strForm = "frmMain") Then
            DoCmd.Close acForm, strForm, acSaveNo
        End If
        ' Note any error that occurred
        If Err <> 0 Then intErr = -1
  Next i
  Exit Sub
ErrExit:
  ' handle errors or maybe just resume
  Resume Next
End Sub

Best,
Jiri
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:58
Joined
May 7, 2009
Messages
19,246
He dont want to shutdown when there is a pop up form open.
 

Colman

Registered User.
Local time
Today, 06:58
Joined
Sep 5, 2011
Messages
37
Uncle Gizmo, I wonder if we could pursue your comments a little.

My first database was for handling warranty returns for a manufacturer. Returned items were booked in and repair details logged and subsequently shipping details recorded and despatch paperwork generated.

If you said I should aim for 10 to 20 forms in that database I would think that would be too many.

My current database does the same returns functionality, far more comprehensively, and also does 30 or so other jobs. e.g. Change Control, Serial Number Generation, Equipment Calibration, Documentation Control, to name just four.

Are you suggesting that a single database should never handle this many jobs, or would you stick with 10 to 20 forms regardless of how many jobs it does, or would you revise your 10 to 20 forms proportionally?

Not arguing with you, just trying to get a sense of how far to expect to go with it.
 

Solo712

Registered User.
Local time
Today, 01:58
Joined
Oct 19, 2012
Messages
828
He dont want to shutdown when there is a pop up form open.

Ok, I didn't see that ....probably because I have written a shutdown-on-idle procedure myself and the restriction (no pop forms) makes no sense to me. It defeats the purpose of a forced shutdown (on a peer-to-peer network) which is to free resources held by unattended machines. One way to handle the shutdown politely is by issuing a two-minute (or so) warning to the user on a splash screen and inviting him to hit a key if he wants to continue.

Best,
Jiri
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 06:58
Joined
Jul 9, 2003
Messages
16,353
Are you suggesting that a single database should never handle this many jobs, or would you stick with 10 to 20 forms regardless of how many jobs it does, or would you revise your 10 to 20 forms proportionally?

I'm not sure it's possible or even desirable to specify how many forms a database should have. However it is common for forms to be spawned all over the place! That's the point really, try and repurpose a form so that it is used more than once.

Another place you see this "spawning of forms" is in the use of subforms. You have one subform on one tab with a particular record source, then an exact copy of the same form, but on another tab with another record source. You could very easily have five or ten subforms like this. All you need is one form (subform) and modify the subform's record source as you load up the main form.

In fact this is a good approach to adopt, because if you have a form with an active record source, then that record source is drawing data down. So if you had 10 tabs with 10 separate forms then you've got 10 hits on the data. A better approach is to endeavour to have the subform's record sources set to nothing "",only add a record source to the subform that is currently being displayed on the tab....

I've been meaning to do a set of videos explaining this!
 

Colman

Registered User.
Local time
Today, 06:58
Joined
Sep 5, 2011
Messages
37
Hi Jiri. Thanks for your input.

I'm not wanting to close any forms and not wanting to close the app. I simply want a logged in user to be logged out after a short period (with a 1 minute warning) so that another user doesn't inadvertently use their log in to perform transactions. The reason for not wanting it to happen while a popup is open is that an open pop-up form could indicate a partially completed transaction which I would not want to interrupt.

Regards
Colman
 

Colman

Registered User.
Local time
Today, 06:58
Joined
Sep 5, 2011
Messages
37
Uncle Gizmo, many thanks for that. I do find your comments extremely interesting and helpful and look forward to seeing some videos if you get around to it.

Regards
Colman
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:58
Joined
Sep 21, 2011
Messages
14,440
Tony,

I'd be interested in this approach, especially as I am using the emulated split form more and more, but how would I handle different number of columns, headers and the like?

I'm not sure it's possible or even desirable to specify how many forms a database should have. However it is common for forms to be spawned all over the place! That's the point really, try and repurpose a form so that it is used more than once.

Another place you see this "spawning of forms" is in the use of subforms. You have one subform on one tab with a particular record source, then an exact copy of the same form, but on another tab with another record source. You could very easily have five or ten subforms like this. All you need is one form (subform) and modify the subform's record source as you load up the main form.

In fact this is a good approach to adopt, because if you have a form with an active record source, then that record source is drawing data down. So if you had 10 tabs with 10 separate forms then you've got 10 hits on the data. A better approach is to endeavour to have the subform's record sources set to nothing "",only add a record source to the subform that is currently being displayed on the tab....

I've been meaning to do a set of videos explaining this!
 

Solo712

Registered User.
Local time
Today, 01:58
Joined
Oct 19, 2012
Messages
828
Hi Jiri. Thanks for your input.

I'm not wanting to close any forms and not wanting to close the app. I simply want a logged in user to be logged out after a short period (with a 1 minute warning) so that another user doesn't inadvertently use their log in to perform transactions. The reason for not wanting it to happen while a popup is open is that an open pop-up form could indicate a partially completed transaction which I would not want to interrupt.

Regards
Colman

I am sorry Colman, you have completely lost me. At any rate, I wish you good luck.

Best,
Jiri
 

isladogs

MVP / VIP
Local time
Today, 06:58
Joined
Jan 14, 2017
Messages
18,261
Colman,

From your last comment that I also don't understand, I'm wondering whether your users are sharing the same copy of the database or if it is split, that they are all using the same copy of the front end.

If either of these are true in a multi user environment, you are asking for trouble.

If the db is split with each user having their own copy of the front end, I think the whole point of this thread would become redundant
 

Colman

Registered User.
Local time
Today, 06:58
Joined
Sep 5, 2011
Messages
37
Hi ridders.

My database is indeed split with each station having its own copy of the front-end. I think what is confusing people is that each station is in a factory environment and in some instances it is shared by a number of people.

In order to restrict some database features to certain people, and also to allow names to be automatically recorded against some database transactions, I developed it to require that users log in with a password before they can do certain things.

This is not really important for anyone to understand except those using the database so forgive me for not explaining further.

Thanks to all for your help.
 
Last edited:

Solo712

Registered User.
Local time
Today, 01:58
Joined
Oct 19, 2012
Messages
828
Hi ridders.

My database is indeed split with each station having its own copy of the front-end. I think what is confusing people is that each station is in a factory environment and in some instances it is shared by a number of people.

In order to restrict some database features to certain people, and also to allow names to be automatically recorded against some database transactions, I developed it to require that users log in with a password before they can do certain things.

Hi Colman,
forgive me but my curiosity is picqued. First off, I don't understand your use of the term "transaction". When we speak of databases, "transaction" means something quite specific: see here https://en.wikipedia.org/wiki/Database_transaction

If you understand the term then you will also understand that making transactions dependent on logins does not make any sense and that ridders has every right to be confused. However, I have taken your use of the term "transaction" liberally, meaning perhaps some "action" performed on the database that is tied to the user log-in. Well if that is the case, ridders is correct also, because if a user begins an operation (on the shared back-end) and walks away from it while it is incomplete without the timer catching it in an inconsistent state and disposing of it automatically, is asking for trouble. Finally, you said:

Colman said:
I'm not wanting to close any forms and not wanting to close the app. I simply want a logged in user to be logged out after a short period (with a 1 minute warning) so that another user doesn't inadvertently use their log in to perform transactions. The reason for not wanting it to happen while a popup is open is that an open pop-up form could indicate a partially completed transaction which I would not want to interrupt.

So, again it sounds like some sort of lock is placed on part of the back-end which is login dependent, and which you don't want to interrupt simply on the suspicion there may be an active operation. But then of course logging the user out WHEN THIS IS NOT HAPPENING does not serve any purpose, or at any rate, any purpose that you told us about. Unless, of course, you want to tell us that your users log in with each others' log-in credentials.

Best,
Jiri
 

Users who are viewing this thread

Top Bottom