Disable all controls in the body part of a form

L

Lorenzo

Hello there,
I have a question. Is it possible through code disabling all the controls
on the BODY part of a mainForm ? Let's add I have also 3 subForms that I
would like to disable too. I would like to perform this task from a
comboBox on the header of my form. The cbo says "activate" and "deactivate"
and is here where I would like to disable the controls in the form. I know
it is possible to hide it through the visible property but I fear that
disabling with one call is a little more complicated. I have in mind a loop
but it is off my capabilities to write the code by myself.

One more thing, when I set via code the bacgroundColor property of the
body of the form it does not get refreshed right away. I tried either with
refresh or repaint but there is no way to accomplish it, I need to save the
form and move to the next or prev record to see the effective change take
place.

Lorenzo,
 
B

Bob Howard

I never tried that, but I do have code that disables all the controls one at
a time. I had to define a dummy control that was visible, however --- I
needed to move the (sub)form's focus to that before disabling the controls
since you cannot disable or hide a control that has the focus. The dummy
control must be visible to satisfy Access's requirements, but I made it the
same color as the background so the user doesn't see it.
 
L

Lorenzo

Ciao Bob,
thanks for your quick reply. How did you disable the controls one at time?
For example just setting the following to each control you want to disable?

frmMyForm.MyControl.enable = False

If so I would need to go through each one of them and I thought there was
an easier way. I actually don't even need to create the dummy control since
I would shift the focus on a control on the header part of the form that I
keep active.

Do you have any suggestion for the second question regarding the background
property that I can't update at run-time?

Lorenzo
 
D

Dirk Goldgar

Lorenzo said:
Hello there,
I have a question. Is it possible through code disabling all the
controls on the BODY part of a mainForm ? Let's add I have also 3
subForms that I would like to disable too. I would like to perform
this task from a comboBox on the header of my form. The cbo says
"activate" and "deactivate" and is here where I would like to disable
the controls in the form. I know it is possible to hide it through
the visible property but I fear that disabling with one call is a
little more complicated. I have in mind a loop but it is off my
capabilities to write the code by myself.

Something like this in the appropriate event procedure:

'----- start of code snippet -----

On Error GoTo Err_Handler

Dim ctl As Access.Control

For Each ctl In Me.Detail.Controls
ctl.Enabled = False
Next ctl

Exit_Point:
Exit Sub

Err_Handler:
If Err.Number = 438 Then
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End If

End Sub
'----- end of code snippet -----
One more thing, when I set via code the bacgroundColor property of
the body of the form it does not get refreshed right away. I tried
either with refresh or repaint but there is no way to accomplish it,
I need to save the form and move to the next or prev record to see
the effective change take place.

That's not what happens for me. Please post your code; maybe there's
something you overlooked. What event do you use to set the BackColor?
 
L

Lorenzo

Hey Dirk,
thanks a lot of this great code snippet...it works just fine I mean just
what I really needed !!!
I have also solved the background color issue...

Private Sub cboStatoPrenotazione_Change()
On Error GoTo Err_Handler

Dim ctlCorpo As Access.Control


If Me.cboStatoPrenotazione = 1 Then
MsgBox ("Sono attiva")
Me.cmdModificaStato.SetFocus
Me.cboStatoPrenotazione.Enabled = False

For Each ctlCorpo In Me.Corpo.Controls
ctlCorpo.Enabled = True
ctlCorpo.Locked = False
Next ctlCorpo

Me.Corpo.BackColor = 15329769
Form_subFrmExtra.Corpo.BackColor = 15329769
Me.cmdSbloccaData.Enabled = True

Else

....more code

plus I have added to the Form_Current a do while to make sure whenever I
open the form I keep everything updated like this



Do While Form_frmPrenotazioni.cboStatoPrenotazione = 2

Form_frmPrenotazioni.Corpo.BackColor = 10922917

For Each ctlCorpo In Form_frmPrenotazioni.Corpo.Controls
ctlCorpo.Enabled = False
ctlCorpo.Locked = True
Next ctlCorpo

Form_frmPrenotazioni.cmdSbloccaData.Enabled = False
Exit Do
Loop


One of the reasons I strive to improve my skills in programming is for one
day be so helpful like you guys, thank you.
Lorenzo
 
D

Dirk Goldgar

Lorenzo said:
Hey Dirk,
thanks a lot of this great code snippet...it works just fine I mean
just what I really needed !!!

Glad to help, Lorenzo. By the way, I just noticed that you included
what looks like your real e-mail address in your messages. I recommend
that you not do that. Viruses and spammers harvest e-mail addresses
from newsgroup postings, so most people protect themselves either by
using a "spam trap" e-mail address that is not used for anything else,
or by modifying their real address for posting, in some way that a human
will know how to fix it, but a virus or spambot will not. See the
address I used in this post for an example.
 

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