+ Reply to Thread
Results 1 to 6 of 6

Prevent User Input into ActiveX text box

  1. #1
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Prevent User Input into ActiveX text box

    I have an ActiveX text box on a worksheet. This box is filled from code that runs on another worksheet. It is not filled from a cell. I want to prevent a user from clicking in the text box and changing anything.

    If I set the Enabled property to False, the data in the box is greyed out which I don't want.

    There is no event (i.e. TextBox_OnFocus) that I know of that can give an error message and then select another text box.

    I had though about code similar to the following:

    Please Login or Register  to view this content.
    This doesn't kill the key entry though. It still puts whatever was typed into the text box, it just tells the user they weren't supposed to do this.

    I tried combining this with a _LostFocus event that reinputs the correct value in the text box but for some reason exiting the message box and having the code activate TextBox7 isn't being interpreted as a LostFocus event.

    Any help would be apprecited. Either no grey text in a disabled text box or a kill key command in the KeyDown event or a way to get the LostFocus event to run properly would be appreciated.

    Thank you,

    Brian

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Prevent User Input into ActiveX text box

    Instead of a textbox, why not use a label?
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Prevent User Input into ActiveX text box

    Labels will work. I used Label.Caption to change the data shown in the label. I have the following code to clear the text boxes:

    Please Login or Register  to view this content.
    This obviously won't clear the labels as we are working with captions and not values.

    I tried the following code which will run with no errors but doesn't modify the label:

    Please Login or Register  to view this content.
    Any help on clearing the labels?

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Prevent User Input into ActiveX text box

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Prevent User Input into ActiveX text box

    Very cool. Thank you.

    Never worked with labels before. Seems like a good solution for an uneditable text box to me.

    One nit picky thing. With text boxes there is an internal margin at the beginning of the box before the text (a small space between the text box edge and where the text begins).

    With labels, the caption is jammed up agains the edge of the label. With my labels and text boxes I have the sunken special effect turned on so this difference is noticeable. I would like to line up my text boxes and labels and then have the text line up and look neat. Is there a way to modify the internal margin of the label to correspond to that of the text boxes?

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Prevent User Input into ActiveX text box

    Not that I'm aware of, but you should be able to add a space or two (or however many are needed) in front of the caption text to get it lined up:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1