Help explain to me

  • Thread starter Thread starter Amin
  • Start date Start date
A

Amin

please just explain what these code do on the northwind database
i have numbered them

Option Compare Database
Option Explicit

(1)
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view
' or Datasheet view.
Dim oAccessObject As AccessObject

Set oAccessObject = CurrentProject.AllForms(strFormName)
If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then
IsLoaded = True
End If
End If
End Function

(2)
Sub ForEachExample()
Dim objAccess As AccessObject
For Each objAccess In CurrentProject.AllForms
Debug.Print objAccess.Name
intCtr = intCtr + 1
Next
End Sub

(3)
Sub WhatsLoaded()
Dim intCtr As
For intCtr = 0 To Forms.Count - 1
Debug.Print intCtr & " - " & Forms(intCtr).Name
Next intCtr
End Sub


(4)
Sub FormState()
Dim accForm As AccessObject
For Each accForm In CurrentProject.AllForms
Debug.Print accForm.Name & _
" Open = " & accForm.IsLoaded
Next accForm
End Sub
 
Amin -

(1) This function tests to see if a form is open or not. You might use this
if you want to close a form. If you try to close the form when it is not
open, you get a run-time error. This function will let you see if the form
is open first.

(2) This subroutine will print (to the immediate window) each of the forms
in your current project. The immediate window is available when you have a
code window open. While this code does not really do anything useful for the
project, it provides a sample of the For Each construct that you could use to
loop through all objects in a collection for some other purpose.

(3) This subroutine loops through the collection of loaded forms and give
number of the form within the collection and the name of the form. This
number is only associated with this form at the time this code is run. This
again prints the results to the immediate window (by using debug.print), so
is meant as an example and not for real functionality within the database.

(4) This subroutine loops through all forms in the current project and
prints (to the immediate window) the form name and whether or not the form is
loaded. This is sample code to show the use of the IsLoaded property of
forms and also how to loop through all the forms in the project.
 
Daryl S said:
If you try to close the form when it is not open, you get a run-time
error.

Actually, you don't. Try it and see.

But I don't mean to criticize the rest of your excellent post.
 
Back
Top