Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Jul 2002
    Location
    Wellington, New Zealand
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Confusion with activecontrol (Word 2k sr1)

    I am trying to automate formating in text boxes on a document with 7 forms.
    I am using a wizard like process to step the user through data entry . Due to the amount of information I have had to split to several forms rather than use a multipage control, though mpg is used. In the "map" area I use text boxes as lables to allow me to use activecontrol ( therefore cut and paste into the individual forms without editing) for navigation.

    My problem is that I wish do use the same logic for formating the individual text boxes....but for some reason activecontrol is behaving strangely
    It seems that if the textbox is on a multipage page then activecontrol doesn't recognise it?
    Does anyone know a workaround
    Thanks in advance.

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Confusion with activecontrol (Word 2k sr1)

    If you look at the help file for active control, you will see that it applies to a UserForm, a frame, or a page. So, if you are in a multipage or a frame, me.activecontrol will give you the name of the multipage or the form, so you'll need something like:
    <pre> Debug.Print Me.ActiveControl.Name
    If Me.ActiveControl.Name = "mp" Then ' In multipage
    Debug.Print Me.mp.Pages(mp.Value).ActiveControl.Name
    End If</pre>

    You could even get fancy and not use the mp (which was the name of my multipage):
    <pre> Debug.Print Me.ActiveControl.Name
    If TypeOf Me.Controls(Me.ActiveControl.Name) Is MultiPage Then
    With Me.Controls(Me.ActiveControl.Name)
    Debug.Print .Pages(.Value).ActiveControl.Name
    End With
    End If</pre>

    Does that help? Did you know that you can define a class and have only one event handler for all of your textboxes? --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    Lounger
    Join Date
    Jul 2002
    Location
    Wellington, New Zealand
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Confusion with activecontrol (Word 2k sr1)

    Your last sentance seems like a solution I need to investigate.

    Will let you know how it goes

    Thanks

  4. #4
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Confusion with activecontrol (Word 2k sr1)

    I'll construct an example class. Be back in 15. --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  5. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Confusion with activecontrol (Word 2k sr1)

    OK, I'll "begining at the beginning..."
    This is modeled after http://j-walk.com/ss/excel/tips/tip44.htm
    In VBA, Insert | Class Module, and enter this code:
    <pre>Option Explicit

    Public WithEvents TextControl As MSForms.TextBox

    Private Sub TextControl_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
    ByVal Shift As Integer)
    Select Case KeyCode
    Case vbKeyReturn
    MsgBox "Work with " & TextControl.Name & vbCr & _
    "which contains " & TextControl.Text
    End Select
    End Sub</pre>


    Then, create a userform with some textboxes. Put some of them in a multipage.

    In the userform code, enter:
    <pre>Option Explicit
    Dim txtBoxes() As New cText
    Dim lngTBcount As Long

    Private Sub UserForm_Initialize()
    Dim c As Control
    For Each c In Controls
    If TypeOf c Is TextBox Then
    lngTBcount = lngTBcount + 1
    ReDim Preserve txtBoxes(1 To lngTBcount)
    Set txtBoxes(lngTBcount).TextControl = c
    End If
    Next c
    End Sub</pre>


    I've attached an example. Holler back if you can't get it to do what you really want to do. HTH --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  6. #6
    Lounger
    Join Date
    Jul 2002
    Location
    Wellington, New Zealand
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Confusion with activecontrol (Word 2k sr1)

    That does the trick. I guess this week will be easier than expected..Thanks both of you

Posting Permissions

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