Using a sub procedure to change a subform property

I

ISSB Programmer

I am currently using the following code to change the AllowEdits property on
any form. The form calls the Sub procedure through a button's OnClick event.

Sub UnlockForm(strFormName As String)
On Error GoTo Err_unlockform
If Forms(strFormName).AllowEdits = False Then
Forms(strFormName).AllowEdits = True
MsgBox "Form is now unlocked for editing."
End If

Exit_unlockform:
Exit Sub

Err_unlockform:
MsgBox Err.Description
Resume Exit_unlockform

End Sub


I am trying to call this Sub procedure from a button on a subform. I was
going to use an if/else statement to execute the following code if the
calling form is a subform:

If Forms(strFormName)(strSubFormName).AllowEdits = False Then
Forms(strFormName)(strSubFormName).AllowEdits = True
MsgBox "Form is now unlocked for editing."
End If


Is there an easier way of doing this? Can I set strFormName to somehow point
to the subform instead of creating another parameter? Thanks.
 
I

ISSB Programmer

Does

NameOfSubformControl = MainFormName

or

NameOfSubformControl = MainFormName!SubFormName

If so does the new procedure look like this:

Sub UnlockForm(strFormName As String)
On Error GoTo Err_unlockform
If me.strFormName.AllowEdits = False Then
me.strFormName.AllowEdits = True
MsgBox "Form is now unlocked for editing."
End If

Exit_unlockform:
Exit Sub

Err_unlockform:
MsgBox Err.Description
Resume Exit_unlockform

End Sub


And do I call the procedure with the following line:

UnlockForm("fsubSubForm")
 
A

Arvin Meyer [MVP]

Me = Forms!FormName

ISSB Programmer said:
Does

NameOfSubformControl = MainFormName
No


or

NameOfSubformControl = MainFormName!SubFormName

No

The full syntax, without the "Me" shortcut would be:

If Forms!MainFormName!SubformControlName.Form.AllowEdits = False

you need to subsitute the appropriate names for the name of the main form
and the name of the subform control. Note that the name of the subform
control and the subform name can be the same or different.
 
I

ISSB Programmer

Thanks for clearing that up. How would I use that in a subprocedure that the
form calls? Is there a way to substitute

Forms!MainFormName!SubformControlName

with an input parameter such as (strControlPathName as String)?
 

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