Passing a form name to forms collection subroutine

O

OPar

I am trying to create a subroutine that will set some properties on
the specified form. Can someone help me with my forms collection
syntax? I want to be able to pass the form name to the subroutine.
This subroutine will be used multiple times which is why I don't want
to place custome code in each form. Can anyone help? Below is an
example of what I am trying to do.


Sub DisableDelete(strFormName as string)

'Disables record delete on specified form
forms(strFormName).DisableDelete = True

End sub
 
G

Guest

Your Sub will need to be Public.

What is .DisableDelete ?

Will the form, whose property you want to change, be open?

Steve
 
M

Marshall Barton

OPar said:
I am trying to create a subroutine that will set some properties on
the specified form. Can someone help me with my forms collection
syntax? I want to be able to pass the form name to the subroutine.
This subroutine will be used multiple times which is why I don't want
to place custome code in each form. Can anyone help? Below is an
example of what I am trying to do.


Sub DisableDelete(strFormName as string)

'Disables record delete on specified form
forms(strFormName).DisableDelete = True

End sub


I never heard of that property, otherwise that is the way to
do it for an open form. However, because subforms are not
in the Forms collection, it will not work for a form being
displayed as a subform.

If you can get each form to call the procedure, you would
be better off passing the form object instead of its name:

Sub DisableDelete(frm as Form)

'Disables record delete on specified form
frm.AllowDeletions = False

End sub

Then, instead of calling it with something like:
DisableDelete Me.Name
or
DisableDelete "main form"

You would call it this way
DisableDelete Me
or
DisableDelete Forms![main form]
or
DisableDelete Forms![main form].[subform control].Form
 

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