dbTalk Databases Forums  

No of forms in databeses

comp.databases.ms-access comp.databases.ms-access


Discuss No of forms in databeses in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Phil
 
Posts: n/a

Default No of forms in databeses - 12-14-2011 , 06:06 AM






I Have a main database with 120 forms and a referenced database with 36 forms
- Yes I know its big.

The following code is in a form in the referenced database

Private Sub FormNameX_BeforeUpdate(Cancel As Integer)

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
If obj.Name = FormNameX Then
GoTo Exit_FormNameX_BeforeUpdate
End If
Next obj

MsgBox MsgBox "The form: " & FormNameX & " is not in this database",
vbCritical Cancel = True

Exit_FormNameX_BeforeUpdate:
DoCmd.Hourglass False

End Sub

The user types the name of a form and the routine is used to check that the
form exists, however, this checks only the 120 forms in the main database. I
need all 156 forms checked.

I find it interesting that it regards Application.CurrentProject as the main
daatbase, not the referenced database that this form & module is in.

Phil

Reply With Quote
  #2  
Old   
Sky
 
Posts: n/a

Default Re: No of forms in databeses - 12-14-2011 , 02:18 PM






On 12/14/2011 7:06 AM, Phil wrote:
Quote:
I Have a main database with 120 forms and a referenced database with 36 forms
- Yes I know its big.

The following code is in a form in the referenced database

Private Sub FormNameX_BeforeUpdate(Cancel As Integer)

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
If obj.Name = FormNameX Then
GoTo Exit_FormNameX_BeforeUpdate
End If
Next obj

MsgBox MsgBox "The form: "& FormNameX& " is not in this database",
vbCritical Cancel = True

Exit_FormNameX_BeforeUpdate:
DoCmd.Hourglass False

End Sub

The user types the name of a form and the routine is used to check that the
form exists, however, this checks only the 120 forms in the main database. I
need all 156 forms checked.

I find it interesting that it regards Application.CurrentProject as the main
daatbase, not the referenced database that this form& module is in.

Phil
It seems that you already know that FormNameX exists since you are
running code that is embedded in it. So why would you check this?

Also, it seems that the library would always have every form that the
library has. Same for the front end. So I do not understand what you are
doing. Nor should you be doing it in the BeforeUpdate event of every
change in the form.

Perhaps if you had a table listing all forms that are needed, and a
programmer tool to check that all forms exist, ok. But it would seem
just as easy to simply make the forms.

Anyway, to answer your question, CurrentProject refers to the front end,
similar to CurrentDb. You can use CodeProject instead to refer to the
library code database.

Steve

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: No of forms in databeses - 12-15-2011 , 03:12 AM



On 14/12/2011 20:17:57, Sky wrote:
Quote:
On 12/14/2011 7:06 AM, Phil wrote:
I Have a main database with 120 forms and a referenced database with 36 forms
- Yes I know its big.

The following code is in a form in the referenced database

Private Sub FormNameX_BeforeUpdate(Cancel As Integer)

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
If obj.Name = FormNameX Then
GoTo Exit_FormNameX_BeforeUpdate
End If
Next obj

MsgBox MsgBox "The form: "& FormNameX& " is not in this database",
vbCritical Cancel = True

Exit_FormNameX_BeforeUpdate:
DoCmd.Hourglass False

End Sub

The user types the name of a form and the routine is used to check that the
form exists, however, this checks only the 120 forms in the main database. I
need all 156 forms checked.

I find it interesting that it regards Application.CurrentProject as the main
daatbase, not the referenced database that this form& module is in.

Phil

It seems that you already know that FormNameX exists since you are
running code that is embedded in it. So why would you check this?

Also, it seems that the library would always have every form that the
library has. Same for the front end. So I do not understand what you are
doing. Nor should you be doing it in the BeforeUpdate event of every
change in the form.

Perhaps if you had a table listing all forms that are needed, and a
programmer tool to check that all forms exist, ok. But it would seem
just as easy to simply make the forms.

Anyway, to answer your question, CurrentProject refers to the front end,
similar to CurrentDb. You can use CodeProject instead to refer to the
library code database.

Steve



Thanks Steve

Obviously I didn't make myself clear.
FormNameX is the name of a Bound Control on a form
As you surmised, this needs to contain the name of a valid form within either
the main database or the referenced Db. Basically I need the ability to build
a list of every form within the 2 databases, but in practice I only need the
names of half a dozen relevant ones. To explain further, I use the same FE
database for a number of organisations, and "tailor" certain forms when they
open, usually by hiding fields that are not relevant to that organisation. I
have a table of TblForm and a table HideFields of the Fields to hide. The
FormNameX holds the name of those forms that I wish to tailor, and then I
have a combo box that lists the fields on that form that I wish to hide.
Anyway have taken up your suggestion and run another loop to check the forms
in CodeProject and this appears to work OK. Not that it’s relevant, but AFIK,
if the form doesn’t have a module, it won’t show up in the CodeProject, so
the method is not completely watertight.

Phil

Reply With Quote
  #4  
Old   
Jon Lewis
 
Posts: n/a

Default Re: No of forms in databeses - 12-15-2011 , 06:07 AM



You can use the following to list all Forms. They don't have to have
modules (or be open).

Dim db As DAO.Database, i As Integer
Set db = CurrentDb 'or CodeDb or use OpenDatabase to open a separate Db
For i = 0 To db.Containers("Forms").Documents.Count - 1
Debug.Print db.Containers("Forms").Documents(i).Name
Next
Set db = Nothing

HTH

"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote

Quote:
On 14/12/2011 20:17:57, Sky wrote:
On 12/14/2011 7:06 AM, Phil wrote:
I Have a main database with 120 forms and a referenced database with 36
forms
- Yes I know its big.

The following code is in a form in the referenced database

Private Sub FormNameX_BeforeUpdate(Cancel As Integer)

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
If obj.Name = FormNameX Then
GoTo Exit_FormNameX_BeforeUpdate
End If
Next obj

MsgBox MsgBox "The form: "& FormNameX& " is not in this database",
vbCritical Cancel = True

Exit_FormNameX_BeforeUpdate:
DoCmd.Hourglass False

End Sub

The user types the name of a form and the routine is used to check that
the
form exists, however, this checks only the 120 forms in the main
database. I
need all 156 forms checked.

I find it interesting that it regards Application.CurrentProject as the
main
daatbase, not the referenced database that this form& module is in.

Phil

It seems that you already know that FormNameX exists since you are
running code that is embedded in it. So why would you check this?

Also, it seems that the library would always have every form that the
library has. Same for the front end. So I do not understand what you are
doing. Nor should you be doing it in the BeforeUpdate event of every
change in the form.

Perhaps if you had a table listing all forms that are needed, and a
programmer tool to check that all forms exist, ok. But it would seem
just as easy to simply make the forms.

Anyway, to answer your question, CurrentProject refers to the front end,
similar to CurrentDb. You can use CodeProject instead to refer to the
library code database.

Steve




Thanks Steve

Obviously I didn't make myself clear.
FormNameX is the name of a Bound Control on a form
As you surmised, this needs to contain the name of a valid form within
either
the main database or the referenced Db. Basically I need the ability to
build
a list of every form within the 2 databases, but in practice I only need
the
names of half a dozen relevant ones. To explain further, I use the same FE
database for a number of organisations, and "tailor" certain forms when
they
open, usually by hiding fields that are not relevant to that organisation.
I
have a table of TblForm and a table HideFields of the Fields to hide. The
FormNameX holds the name of those forms that I wish to tailor, and then I
have a combo box that lists the fields on that form that I wish to hide.
Anyway have taken up your suggestion and run another loop to check the
forms
in CodeProject and this appears to work OK. Not that it's relevant, but
AFIK,
if the form doesn't have a module, it won't show up in the CodeProject, so
the method is not completely watertight.

Phil

Reply With Quote
  #5  
Old   
Phil
 
Posts: n/a

Default Re: No of forms in databeses - 12-15-2011 , 08:49 AM



On 15/12/2011 12:07:29, "Jon Lewis" wrote:
Quote:
db.Containers("Forms").Documents(i).Name
Thanks, Jon

Much more reliable

Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.