Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    May 2001
    Location
    Blackpool, Lancashire, England
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA programmatic form creation? and setfocus probs (Word 2000)

    Can anyone tell me if it is possible to create a user form programatically in order to create a custom input box as a class object (without an external userform in other words)?
    I seem to be having absolutly shed loads of problems controlling the focus in an overly complex form. The multi page form encompasses a complex decision tree with controls being made available or not throughout the process. Any attempts to control the focus is met with an almost human disdain chossing to step through lines of code taking as much notice as car drivers do to box junctions (sorry an English assumption of understanding there!). I am sure I have covered all event posiblities, but have now retreated non the wiser to pull my hair in frustration and seek wisdom here. Could anyone please give me some pointers to succesful focus control (especially from child forms to parents) Thx JasH

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: VBA programmatic form creation? and setfocus probs (Word 2000)

    If you set a reference (in Tools | References...) to Microsoft Visual Basic for Applications Extensibility 5.3, you can create and manipulate modules, class modules and user forms in code.

    Unfortunately, the online help is less than complete, and the subject is by its nature confusing.

    Here is how to create a user form:

    Dim frm As VBComponent
    Set frm = ActiveDocument.VBProject.VBComponents.Add(Componen tType:=vbext_ct_MSForm)

    Have fun!

  4. #3
    New Lounger
    Join Date
    May 2001
    Location
    Blackpool, Lancashire, England
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA programmatic form creation? and setfocus probs (Word 2000)

    Thx thats certainly a start now to work out how to manipulate it!
    Anyone any ideas about the setfocus issues?
    Chrs JasH

  5. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: VBA programmatic form creation? and setfocus probs (Word 2000)

    There was a thread not so long ago in the Excel forum about problems with SetFocus in userforms; it starts at <post#=277234>post 277234</post#>. Legare Coleman proposed to hide the userform while setting the focus to another control, then unhide it; see <post#=277397>post 277397</post#>. I hope that works for you too.

  6. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VBA programmatic form creation? and setfocus probs (Word 2000)

    Are you adding controls dynamically or are you enabling/disabling/hiding controls that you created at design time? Actually, I'm not sure it would help me to know that. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> But if it's all dynamic, then I think you cannot rely on a "tab order" and have to deal with the Exit event:

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Me.TextBox3.SetFocus
    End Sub

    Can you create new event handlers for dynamically created controls?

    With respect to multipage controls, there was a thread, long time ago, regarding problem setting focus on a subsequent or previous tab. Almost certainly you will want to show the tab before trying to set focus, but any other lessons were lost in dead brain cells.

  7. #6
    New Lounger
    Join Date
    May 2001
    Location
    Blackpool, Lancashire, England
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA programmatic form creation? and setfocus probs (Word 2000)

    The setfocus stuff looks vry interesting, thx i will explore it soon, ref jscher2000, the 2 are seperate issues. The question ref dynamic form creation is in order to encapsulate an error message interface into a class module (if possible) in order to create a series of date validation functions that handle any input errors with a self contained input box like that built into vb/vba. is it possible or am I looking in the totally wrong direction? Thanks all for the help so far, JasH

  8. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VBA programmatic form creation? and setfocus probs (Word 2000)

    I'm having some trouble understanding your message; this could be related to your using parts of words rather than the entire words; I'm not of the instant messaging and text messaging generation. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    So... you want to create a little userform that works like an InputBox but has robust validation. I don't see any difficulty with that in theory. I think you will find it easier to keep most of your validation code in the form's code module, but it should be possible to call code from other modules in the same project. However, I'm not sure that you can put event handlers outside the form's code module; you probably want at least the shell of those in there.

    One other thing, if these dates are being entered by the user, you can use a date control such as the DTPicker to help enforce your rules, but you will need a license to redistribute it (either Visual Basic/Visual Studio, or Office Developer Edition). Third-party date controls also have been mentioned in the past.

Posting Permissions

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