Help explain to me

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
 
D

Daryl S

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.
 
M

Marshall Barton

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

(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

That function does what the comment says it does.
(2)
Sub ForEachExample()
Dim objAccess As AccessObject
For Each objAccess In CurrentProject.AllForms
Debug.Print objAccess.Name
intCtr = intCtr + 1
Next
End Sub

This displays a list of all the forms in the database to the
Immediate Window.
(3)
Sub WhatsLoaded()
Dim intCtr As
For intCtr = 0 To Forms.Count - 1
Debug.Print intCtr & " - " & Forms(intCtr).Name
Next intCtr
End Sub

This one lists all the open forms
(4)
Sub FormState()
Dim accForm As AccessObject
For Each accForm In CurrentProject.AllForms
Debug.Print accForm.Name & _
" Open = " & accForm.IsLoaded
Next accForm
End Sub

This one lists all the forms and a code that indicates if
its open and if its open or not.

You can find a lot of the details about this kind of thing
by reading the VBA Help topic on AccessObject.
 
D

Dirk Goldgar

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top