![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
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 |
#5
| |||
| |||
|
|
db.Containers("Forms").Documents(i).Name |
![]() |
| Thread Tools | |
| Display Modes | |
| |