My Assistant
![]() ![]() |
|
|
Nov 6 2011, 08:23 PM
Post
#1
|
|
|
UtterAccess Veteran Posts: 327 From: Queensland Australia |
Hi Colleagues,
While looking for a way to check for all open forms, there were references to 1.If CurrentProject.AllForms("YourFormName").IsLoaded = True Then ................. End If 2. Dim obj As AccessObject, dbs As Object Set dbs = Application.CurrentProject For Each obj In dbs.AllForms If obj.IsLoaded = True Then ' Print name of obj. Debug.Print obj.Name End If Next obj The first one did not recognize all forms a loaded, even though they were clearly visible on screen BUT the second one worked find even though constructs are very similar. Could you please let me know what I have missed? a. Both have CurrentProject in syntax – not sure what that means as I have not explicitly defined a project - I would not know how to b. Some web sites referred to form mode eg Design – does that have any relevance to syntax? Regards cwac60 |
|
|
|
Nov 6 2011, 08:58 PM
Post
#2
|
|
|
Access Wiki and Forums Moderator Posts: 48,642 From: SoCal, USA |
Hi,
The first syntax is referring to a specific form; whereas, the second syntax referencess "all" the forms in the AllForms collection. If the first syntax did not work for you, try double-checking the name of the form you used in the code. Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Nov 6 2011, 10:03 PM
Post
#3
|
|
|
UtterAccess Veteran Posts: 327 From: Queensland Australia |
Hi theDBGuy
Thank you for the fast response. I did check the name of the form including copy and paste from Navigation window. I used the same way to specifically inside loop of second approach e.g. if obj.name = "frmName" then do something ....... where it qualified. Still mystified by project syntax???? Cheers cwac60 |
|
|
|
Nov 6 2011, 10:42 PM
Post
#4
|
|
|
Access Wiki and Forums Moderator Posts: 48,642 From: SoCal, USA |
Hi,
Can you post the actual code you used so we can see it more clearly? Thanks. |
|
|
|
Nov 7 2011, 07:58 AM
Post
#5
|
|
|
Retired Moderator Posts: 19,667 |
Still mystified by project syntax???? CurrentProject is basically the overall Container for all Access Objects in your database that you can manipulate in code, mainly for hierarchical references. The SubContainers are AllForms, AllReports, AllMacros, etc... and thus the Form references: CurrentProject.AllForms.Item("YourFormName") Since Item is the default Property, it can be omitted and therefore the shortened form is CurrentProject.AllForms("YourFormName") or in fact, you can also use the enumeration operator ! (bang) CurrentProject.AllForms![YourFormName] The CurrentProject is complementary to the CurrentData Object which contains the JET/ACE Objects (subContainers are AllTables, AllQueries, etc...) as distinct from Access. There are more info. in Access VBA Help, if you are interested... |
|
|
|
Nov 9 2011, 09:03 AM
Post
#6
|
|
|
UtterAccess Veteran Posts: 327 From: Queensland Australia |
Hi theDBGuy
Thank you for your assistance. I used the code as per examples on web and included a message box to say whether it was T/F. The code was included in an OnClose event - the aim being to close the form if it were open to stop cluttering screen. If CurrentProject.AllForms("YourFormName").IsLoaded = True Then do something Else: do something else End If I discarded this code and adapted the loop action to perform the task: number of forms to close could be 0, 1 or 2. Only things I could think of was that the form in question had a caption different to name in Navigator. Regards cwac60 |
|
|
|
Nov 9 2011, 09:05 AM
Post
#7
|
|
|
UtterAccess Veteran Posts: 327 From: Queensland Australia |
Hi vtd
thank youn for info on classes as it provides a good starting point to delve deeper into subject. Cheers cwac60 |
|
|
|
Nov 9 2011, 02:32 PM
Post
#8
|
|
|
Retired Moderator Posts: 19,667 |
... and adapted the loop action to perform the task: number of forms to close could be 0, 1 or 2. See if the discussion in the Topic Someone Please Show Me An Easier Way.....Please.... can give you some ideas or the code/code structure to do what you want... |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 19th June 2013 - 10:27 PM |