Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable all fields in the subform based on value in main form 1

Status
Not open for further replies.

ekwstats

MIS
Feb 2, 2004
70
US
I have a record that I don't want to be updated, so I want to disable all of the fields in the subform when this record appears. I can get it to work if I list out each field individually, but is there a way to go through all of the controls on the subform disable them with something like this?
Thanks

Dim ctrl As Control

For Each ctrl In Me.SubForm
ctrl.Enable = False
Next ctrl
 
Why don't you just disallow edits

form.allowedits = false
 
Richard,
Your method works, but it's not obvious to the end user that the form is disabled. I was hoping to gray out all of the controls.

Sophiet,
I get a method or datamember not found error when I try to use AllowEdits
 
Sophiet...the allowedits now works, but it's the same issue, it's not really clear to the user that they can't update those fields because they are not grayed out.
 
Perhaps...
Me.YourSubFrom.Enabled = False
Me.AnUnboundTextFeild = "NO EDITS allowed to subform"

You can get pretty fancy too. Use of colour is a powerful tool. For example, you can standardize background colours for the end user
- cyan - field accepts data
- peach - info only, no edits allowed
- yellow - mandatory field

Using this colour scheme, you can set the colour of the subform to peach...

Me.YourSubFrom.BorderColor = vbRed
Me.YourSubFrom.Form.Section(0).BackColor = 14084847

Obviously, you can come up with your scheme for colours.

You can use a centralized routine to toggle colour and properties depending on edit requirements.

Richard
 
How are ya ekwstats . . . . .

Disabling controls can get a little tricky, espcially with subforms. So try this:

In your subforms header or footer, add an [blue]Unbound TextBox[/blue]. In the properties for it, select the [blue]Other Tab[/blue] and change the [blue]Name Property[/blue] to [purple]ParkCsr[/purple]. Then set its [blue]width & height to zero[/blue].

Next, add the following code to the OnCurrent Event of the mainform (you substitute items in [purple]purple[/purple]):
Code:
[blue]   Dim sfrm As Form, flg As Boolean, ctl As Control
   
   Set sfrm = Me![purple][b]SubFormName[/b][/purple].Form
   sfrm!ParkCsr.SetFocus
   
   If Me![purple][b]MainFormPrimaryKeyName[/b][/purple] = [purple][b]?[/b][/purple] Then
      flg = False
   Else
      flg = True
   End If
   
   If Not sfrm![purple][b]AnySubFormTextFieldName[/b][/purple].Enabled = flg Then
      For Each ctl In sfrm.Controls
         If ctl.ControlType = acTextBox And ctl.Name <> "ParkCsr" Then
            ctl.Enabled = flg
         End If
      Next
   End If

   Set sfrm = Nothing[/blue]
[blue]Cheers![/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top