Consulting

Results 1 to 3 of 3

Thread: UserForm - Activate Textfield if OptionButton selected / deactivate when deselected

  1. #1
    VBAX Regular
    Joined
    Jun 2016
    Posts
    45
    Location

    UserForm - Activate Textfield if OptionButton selected / deactivate when deselected

    Hello i am looking for a solution to a problem i am having.

    • I have TextFields in my document.
    • Clicking on of those TextFields activates a certain UserForm correlated to this TextField.
    • Those Userforms contain OptionButtons. (Only one can be active at the same time)
    • Selecting on of those OptionButtons and clicking OK in the UserForm transfers the caption of this OptionButton to the TextField in the document.
    • I want to provide the user with the opportunity to manually enter data into a TextField inside the UserForm, if the provided selections do not fit his needs.
    • To activate this TextField, the user has to activate a certain OptionButton. Then a messagebox pops up and the user has to comply by clicking OK.
    • After clicking OK, the TextField gets enabled and the user can input his data. After clicking OK, the data in the TextField gets transferred to the TextField in the document (just as with the selection of any other OptionButton).

    My current Problem is:
    • When the user has activated the TextField by clicking the necessary OptionButton, i want the Textfield to deactivate again if the user is selecting a different OptionButton. (Currently the TextField just stays activated).

    Does anyone have an idea how i can implement that functionality into the UserForm?


    Another thing is (no high priority):
    • I am having a lot of different TextFields in my Document, each activating different UserForms with different amounts of OptionButtons and content.
    • Implementing this new functionality would require me to edit each single UserForm, which is quite tedious.

    I am wondering if one of you experts would know of a way to propably optimize or rewrite this whole process in a way to make it more uniform - So that it would not be required to edit each UserForm manually?

    I have attached a test document to this post. So if someone could take a look at it, that would be awesome!

    UserformTest2.zip


    Greetings

    Manuel

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,063
    Location
    You could use the change event:

    Private Sub OptionButton3_Change()
      If OptionButton3 Then
        If MsgBox("Achtung! Durch aktivieren dieser Schaltfläche wird die Eingaberestriktion aufgehoben - " & _
                  "Der Benutzer ist für die korrekte Anwendung dieser Funktion verantwortlich - " & _
                  "Diese Funktion sollte nur verwendet werden, wenn oben aufgeführte Auswahlmöglichkeiten nicht zutreffend sind.", _
                  vbOKCancel, "Manuelle Benutzereingabe") = vbOK Then
          customInput.Enabled = True
          customInput.BackColor = RGB(255, 255, 255)
        End If
      Else
        customInput.Enabled = False
        customInput.BackColor = &H8000000C
        customInput.Text = ""
      End If
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Regular
    Joined
    Jun 2016
    Posts
    45
    Location
    Wonderful,
    it is working! Simple solution =)

    Thanks Greg

Posting Permissions

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