Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

Using a sub procedure to change a subform property

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ISSB Programmer - 26 May 2007 02:41 GMT
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.
Arvin Meyer [MVP] - 26 May 2007 03:29 GMT
If Me.NameOfSubformControl.AllowEdits = False Then
Signature

Arvin Meyer, MCP, MVP
Microsoft Access
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

>I am currently using the following code to change the AllowEdits property
>on
[quoted text clipped - 29 lines]
> point
> to the subform instead of creating another parameter? Thanks.
ISSB Programmer - 26 May 2007 03:43 GMT
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")

> If Me.NameOfSubformControl.AllowEdits = False Then
Arvin Meyer [MVP] - 29 May 2007 12:00 GMT
Me = Forms!FormName

> 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.
Signature

Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

> If so does the new procedure look like this:
>
[quoted text clipped - 19 lines]
>
>> If Me.NameOfSubformControl.AllowEdits = False Then
ISSB Programmer - 30 May 2007 00:22 GMT
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)?

> The full syntax, without the "Me" shortcut would be:
>
[quoted text clipped - 3 lines]
> 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.
Arvin Meyer [MVP] - 30 May 2007 14:21 GMT
The same code that you wrote should work. What you need to use though is the
control name, not the form name. Often they are the same, but if they are
different, the form name won't work. To me sure, select the subform in
Design View, then check the Name property on the Other tab of the property
sheet.
Signature

Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

> Thanks for clearing that up. How would I use that in a subprocedure that
> the
[quoted text clipped - 11 lines]
>> 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.