Lock text boxes inside of Mulitpage

Dalton325

New Member
Joined
Mar 18, 2015
Messages
10
Hello everyone.

I did an internet search and a search on this site before posting this. I couldn't find an answer to my question. I may not have been putting in the correct criteria, though.

I have a userform that is pulling information from a spreadsheet. It's for viewing a products information. I have an edit button outside of the multipage. Instead of creating two identical forms and having a viewing one that is locked down and an editable one, I'd like to just use one form and make it where the users can't edit the data in the textboxes, listboxes, option buttons, etc...

I have found a solution to this by writing code for each text box, such as: txtName.locked=true.

That allows me to keep the user from editing it. I can then unlock it when they hit the edit button and make the edit button invisible while making a save button visible, or maybe just changing the text. I haven't decided yet.

Anyway, I don't have a lot of controls on this form, but I'd still like something more elegant than coding a lock for every text box and control on each page. Ideally, I'd like to be able to do something like: MultiPage1.tabBasic.locked = true.

That would lock down the whole tab without making it invisible. VBA doesn't like me when I try that, though. I've also found the code for disabling the entire tab, but that doesn't work because it's not visible to the user. I'd like them to be visible and not greyed out, which is why I'm using locked instead of enabled.

Even this solution isn't ideal as the cursor still appears in the text boxes, even if you can't edit them. Can anyone help me with this issue? Thanks.

Dalton325
 
Maybe something like this:

Code:
   [COLOR=#0000ff] Dim[/COLOR] ctrl [COLOR=#0000ff]As[/COLOR] Control
[COLOR=#0000ff]
[/COLOR]
[COLOR=#0000ff]    On Error Resume Next[/COLOR]
[COLOR=#0000ff]    For Each[/COLOR] ctrl [COLOR=#0000ff]In[/COLOR] Me.Controls
        ctrl.Locked = [COLOR=#0000ff]True[/COLOR]
   [COLOR=#0000ff] Next [/COLOR]ctrl
[COLOR=#0000ff]    On Error GoTo 0[/COLOR]

This URL may help: Excel VBA: Loop Through Controls on a UserForm. Textbox, ComboBox, CheckBox etc

Just remember all controls can't be locked. That is why On Error Resume Next is in the code (it bypasses controls that can't be locked without raising an error)
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top