Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    I've tried -
    For each frm in Forms
    debug.print frm.name
    Next

    But of course this only finds forms which are currently open.

    How do I list all forms even if they are closed?

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    In order to do that you need to refer to the AllForms Collection. See MSDN AllForms Collection for the details and an example of exactly how to list all forms in a database or a project. It is specific to Access 2003 but other version work in a similar fashion.
    Wendell

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    [quote name='WendellB' post='792064' date='04-Sep-2009 13:56']In order to do that you need to refer to the AllForms Collection. See MSDN AllForms Collection for the details and an example of exactly how to list all forms in a database or a project. It is specific to Access 2003 but other version work in a similar fashion.[/quote]
    Thanks Wendell, that's what I wanted.

  4. #4
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    [quote name='WendellB' post='792064' date='04-Sep-2009 13:56']In order to do that you need to refer to the AllForms Collection. See MSDN AllForms Collection for the details and an example of exactly how to list all forms in a database or a project. It is specific to Access 2003 but other version work in a similar fashion.[/quote]

    I'm having problems trying to find the desctription property of the form.
    I'm using the name of the allforms object to open the form and I can then get all the other properties but I just can't find the description.

  5. #5
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    Try the example shown in MSDN Properties Collection - it should enumerate the properties of a form if you have one open, and give you the name of each property.
    Wendell

  6. #6
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    [quote name='WendellB' post='792175' date='05-Sep-2009 04:34']Try the example shown in MSDN Properties Collection - it should enumerate the properties of a form if you have one open, and give you the name of each property.[/quote]
    Thanks Wendell but I'd already iterated throught the properties collection, but the Description if not there.
    I've checked both the properties of AllForms and of open forms. No Description property.
    Any ideas as to where else I might find it?

  7. #7
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Here is a function that will return the Description property of a form. I found this Here

    Code:
     Function FormDescription(FormName As String, Optional DefaultDescription = Empty, Optional ClearDescription As Boolean = False) As String
    	 Dim loDb   As DAO.Database
    	 Dim loForm As DAO.Document
    	 Dim loProp As DAO.Property
    	 Dim strRet As String
     
    	 On Error GoTo FormDescription_err
    	 Const PROP_NAME_DESCRIPTION = "Description"
    	 Const CONTAINER_FORMS = "Forms"
     
    	 strRet = vbNullString
    	 Set loDb = CurrentDb
    	 Set loForm = loDb.Containers(CONTAINER_FORMS).Documents(FormName)
     
    	 If Not ClearDescription Then
    		 strRet = loForm.Properties(PROP_NAME_DESCRIPTION)
    	 Else
    		 On Error Resume Next
    		 With loForm.Properties
    			 .Delete PROP_NAME_DESCRIPTION
    			 .Refresh
    		 End With
    		 On Error GoTo FormDescription_err
    	 End If
     FormDescription_end:
    	 On Error Resume Next
    	 Set loForm = Nothing
    	 Set loDb = Nothing
    	 Set loProp = Nothing
    	 FormDescription = strRet
    	 Exit Function
     
     FormDescription_err:
    	 Select Case Err
    		 Case 3265	'Item not found in this collection.
    			 MsgBox "The form " & FormName & " does not exist."
    		 Case 3270	'Property not found.
    			 If IsEmpty(DefaultDescription) Then
    				 strRet = vbNullString
    			 Else
    				 If Len(DefaultDescription) > 0 Then
    					 With loForm
    						 Set loProp = .CreateProperty(PROP_NAME_DESCRIPTION, dbText, DefaultDescription)
    						 With .Properties
    							 .Append loProp
    							 .Refresh
    						 End With
    					 End With
    					 Resume
    				 Else
    					 strRet = vbNullString
    				 End If
    			 End If
    		 Case Else
    			 MsgBox Err.Description
    	 End Select
    	 Resume FormDescription_end
     End Function

    Then this will loop through each form in Allforms, print its name and Description.

    Code:
     Private Sub Command70_Click()
    	 
    	 Dim strDescription As String
    	 Dim obj As AccessObject, dbs As Object
    	 Set dbs = Application.CurrentProject
    	 ' Search for open AccessObject objects in AllForms collection.
    	 For Each obj In dbs.AllForms
    		Debug.Print obj.Name
    		strDescription = FormDescription(obj.Name)
    		Debug.Print strDescription
    	  Next obj
     
     End Sub
    Regards
    John



  8. #8
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    [quote name='johnhutchison' post='792221' date='05-Sep-2009 11:02']Here is a function that will return the Description property of a form. I found this Here

    Code:
     Function FormDescription(FormName As String, Optional DefaultDescription = Empty, Optional ClearDescription As Boolean = False) As String
    	 Dim loDb   As DAO.Database
    	 Dim loForm As DAO.Document
    	 Dim loProp As DAO.Property
    	 Dim strRet As String
     
    	 On Error GoTo FormDescription_err
    	 Const PROP_NAME_DESCRIPTION = "Description"
    	 Const CONTAINER_FORMS = "Forms"
     
    	 strRet = vbNullString
    	 Set loDb = CurrentDb
    	 Set loForm = loDb.Containers(CONTAINER_FORMS).Documents(FormName)
     
    	 If Not ClearDescription Then
    		 strRet = loForm.Properties(PROP_NAME_DESCRIPTION)
    	 Else
    		 On Error Resume Next
    		 With loForm.Properties
    			 .Delete PROP_NAME_DESCRIPTION
    			 .Refresh
    		 End With
    		 On Error GoTo FormDescription_err
    	 End If
     FormDescription_end:
    	 On Error Resume Next
    	 Set loForm = Nothing
    	 Set loDb = Nothing
    	 Set loProp = Nothing
    	 FormDescription = strRet
    	 Exit Function
     
     FormDescription_err:
    	 Select Case Err
    		 Case 3265	'Item not found in this collection.
    			 MsgBox "The form " & FormName & " does not exist."
    		 Case 3270	'Property not found.
    			 If IsEmpty(DefaultDescription) Then
    				 strRet = vbNullString
    			 Else
    				 If Len(DefaultDescription) > 0 Then
    					 With loForm
    						 Set loProp = .CreateProperty(PROP_NAME_DESCRIPTION, dbText, DefaultDescription)
    						 With .Properties
    							 .Append loProp
    							 .Refresh
    						 End With
    					 End With
    					 Resume
    				 Else
    					 strRet = vbNullString
    				 End If
    			 End If
    		 Case Else
    			 MsgBox Err.Description
    	 End Select
    	 Resume FormDescription_end
     End Function

    Then this will loop through each form in Allforms, print its name and Description.

    Code:
     Private Sub Command70_Click()
    	 
    	 Dim strDescription As String
    	 Dim obj As AccessObject, dbs As Object
    	 Set dbs = Application.CurrentProject
    	 ' Search for open AccessObject objects in AllForms collection.
    	 For Each obj In dbs.AllForms
    		Debug.Print obj.Name
    		strDescription = FormDescription(obj.Name)
    		Debug.Print strDescription
    	  Next obj
     
     End Sub
    [/quote]

    Well that's just fantastic. I'd googled my little fingers to the bone and couldn't find anything.

    This does the job. A very big THANKYOU!!
    Kent

  9. #9
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    Just to wrap this up, I'm curious why you wanted to do this to begin with? I presume you are aware of the Document facilities in Access that will do this sort of thing and a fair bit more without writing and VBA.
    Wendell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •