Cesar Aracena
asked on
How can I enable/disable multiple fields with one click in Access 2010?
Hi guys,
I have a form that displays lots of data. Those fields are disabled by default but I want the user to be able to edit them by pressing a button. Right now I'm putting a line for each field in the "Click" event of the button (i.e. Me.FirstName.Enabled = True) but it's driving me insane.
Isn't there a fastest way to tell Access to turn all those disabled fields to enabled at once? I've searched for a method like "DisabledFields" but there's none of that. I've also tried grouping but groups don't have names so... nothing.
Thanks in advance!
I have a form that displays lots of data. Those fields are disabled by default but I want the user to be able to edit them by pressing a button. Right now I'm putting a line for each field in the "Click" event of the button (i.e. Me.FirstName.Enabled = True) but it's driving me insane.
Isn't there a fastest way to tell Access to turn all those disabled fields to enabled at once? I've searched for a method like "DisabledFields" but there's none of that. I've also tried grouping but groups don't have names so... nothing.
Thanks in advance!
Or if you want to enable/disable ALL textboxes at once:
The following modification will toggle controls between enabled and disabled:
Dim ctl as Control
For Each ctl in Me.Controls
If ctl.ControlType = acTextbox
ctl.Enabled = True
End if
The following modification will toggle controls between enabled and disabled:
ctl.Enabled = Not ctl.Enabled
One other way (quite similar to grouping) is to put a Tab control on your form and put the textboxes in a tab page.
Then set the tab control BackStyle to Transparent and the Style to None so that you don't see the tab control.
The you could just use either the name of the Tab control or the name of the page to enable/disable your fields.
Me.NameOfTabControl.Enable d = False
or
Me.NameOfPage.Enabled = False
Then set the tab control BackStyle to Transparent and the Style to None so that you don't see the tab control.
The you could just use either the name of the Tab control or the name of the page to enable/disable your fields.
Me.NameOfTabControl.Enable
or
Me.NameOfPage.Enabled = False
ASKER
Thanks guys.
I'm using (second) mbizup's approach as I need to see the disabled fields but I have a problem. Maybe you can see whats wrong?
Thanks again!
I'm using (second) mbizup's approach as I need to see the disabled fields but I have a problem. Maybe you can see whats wrong?
Private Sub btnAllowEdit_Click()
'Actions
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Enabled = True
End If
Next ctl
'Buttons
Me.btnStopEdit.Visible = True
Me.EmployeeNumber.SetFocus
Me.btnAllowEdit.Visible = False
End Sub
Private Sub btnStopEdit_Click()
'Actions
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Enabled = Not ctl.Enabled
End If
Next ctl
'Buttons
Me.btnStopEdit.Visible = False
Me.EmployeeNumber.SetFocus
Me.btnAllowEdit.Visible = True
End Sub
When I hit the btnAllowEdit button, every textbox becomes enabled and the buttons switch (the SetFocus part is becouse focused buttons can't be hidden) but when I hit the btnStopEdit button... nothing happens. The buttons don't even change... why?Thanks again!
In design view, click the "..." next to on click in btnStopEdit's proeperty sheet. This will ensure that the code is "connected" to its event. Occasionally (especially if you have copy/pasted code), the events are not connected to their code.
I'm suggesting this because it doesn't sound like your code is running at all.
I'm suggesting this because it doesn't sound like your code is running at all.
I'm using (second) mbizup's approach as I need to see the disabled fieldsI'm not following what you mean here. All the solutions posted will not hide the fields but just dIsable them. Can you explain a bit more?
ASKER
Thanks mbizup... I was copy/pasting. It was recorded as macro rofl.
IrogSinta, I read wrong sorry. I thought you said "hide" but still, I have many elements that should be still enabled even after disabling the textboxes. I'm using tabs btw.
mbizup, what if I also want to disable something else besides a textbox? Say an attachment box. What would I need to include in the query? Not very familiar with VB I'm affraid.
IrogSinta, I read wrong sorry. I thought you said "hide" but still, I have many elements that should be still enabled even after disabling the textboxes. I'm using tabs btw.
mbizup, what if I also want to disable something else besides a textbox? Say an attachment box. What would I need to include in the query? Not very familiar with VB I'm affraid.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nevermind... Do you mean the paperclip on the ribbon? I think it is "acAttachment":
Are you disabling ALL of the controls on your form, or just certain types of controls?
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox OR ctl.ControlType = acAttachment Then
ctl.Enabled = Not ctl.Enabled
End If
Next ctl
Are you disabling ALL of the controls on your form, or just certain types of controls?
ASKER
Excellent! Thanks a lot. For Attachments is... acAttachment :P
Savd me lots and lots of lines in VB. TY!!!
Savd me lots and lots of lines in VB. TY!!!
Glad to help out :)
Open in new window