Using Form Name as Varible

A

A Dubey

I am in the process of converting a very large app
(Access XP/2002) with close to 100 forms and sub forms to
have dynamically configured forms.

By this I mean changing control properties depending on
which customer group is selected.

I have already figured out how to do this by using a
table with all of the controls for each form the
appropriate properties etc.

I have written a routine that will open a form in design
view and append my table with all of the pertinate info.

My problem is it will only work if I call it using the
actual form name or Me.
ie: Call BuildForm(Forms!form1)
or Call BuildForm(Me)

Here is some sample code:

'*********************************************************
************************

Public Sub GetForms()
On Error GoTo Err_GetForms
Dim frmStr As Variant
Dim frm As Form
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject

For Each obj In dbs.AllForms
frmStr = obj.name
set frm = frmStr ' This line produces error
Call BuildForm(frm) ' Will Work if
' Set frm = Me (Called from
the actual form -- Not an Option)
' Set frm = Forms!form1 (Where
Form1 is the actual form name)
' I have tried every syntax I
can think of, but can't get it to work.
Next obj

Exit_GetForms:
Exit Sub
Err_GetForms:
MsgBox Err.Description
Resume 'Exit_GetForms
End Sub

'*********************************************************
************************

Public Sub BuildForm(frm As Form)

DoCmd.OpenForm frm, acDesign
'do stuff ( This part of the routine works if I
call in one of these ways.
' Call Buildform(Me)
' Call Buildform(Forms!Form1)
'I cannot seem to get a varible to pass as a Form.
DoCmd.Close acForm, frm.Name, acSaveNo

End Sub

'*********************************************************
************************
 
C

Chris

set frm = forms(frmStr)

That will only work if the form that frmStr references is
open. The AllForms collection will return every form in
the database, but you can't reference them until you open
them.


Chris
 
A

A Dubey

Chris,

Thanks, this will work pefectly. I can Open the form in
design view using the object refference, then use the set
frm = forms(fmrStr) then call the sub.

Thanks Again,

AD
 
A

Albert D. Kallal

Note that you can change/set what the source (form) is a for a sub-form
control.

you an also change the "data source" (what field) a control on the screen
will have. Both of these things can be done without having to change the
form in actual design mode.

I would NOT in ANY circumstances allow code that has to modify the form in
any project I do. Do not consider an application that modifies forms, and
then has to save it. You will have such instability problems, and general
poor performance as to make the whole project a disaster. I would not
attempt this!

So, sure..change the data source of existing controls etc, and you can even
do this with a mde. Any self respecting developer will use mde front end
anyway...and thus you can't open forms in design mode anyway. And, of
course...you data is connected to the data only back end...right?
I have written a routine that will open a form in design
view and append my table with all of the pertinate info.

I see the cliff ahead...and I am posting warning signs...don't even try
this.

If what you are attempting is a one time thing (like some kind of wizard to
create a form), then sure...but as a general application approach..opening
forms in design mode and saving them, and then running that form is not even
close to being reliable, or sustained possible as a serious application in
any way, shape, or form!
 
A

A Dubey

My goal here was to create a refference table of all
controls for all forms in my App. (This has been done.)

Once I have all of the default settings, I can use them
to create dynamic forms depending on a GroupID Varible.

Ie: some field names might need a different lable or may
or may not need to be visible.

I plan to create a table based on form name and groupID
that contains records for just the controls that are
specific to the GroupID.

Then On_Form_Open (not in design mode) I can then
dynamically set the properties for all of the controls
necessary. Making each form dynamically customised for
each group.

I choose to build the ref table by opening the forms in
design mode to eliminate the possibility of conficts with
any form related VBA.

Thanks for the advice.

AD
 

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