Results 1 to 9 of 9

Thread: Create controls in runtime

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    38

    Post

    is it possible in VBA (!) to create controls in runtime ?

    (And I would appreciate it if your answer would be a bit more than just 'yes' or 'no' )

  2. #2
    New Member
    Join Date
    Jul 1999
    Posts
    15

    Post

    If VBA has the method CreateObject or if you already have one control and you want to create a control array use the load method.

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    38

    Post

    I have 1 image control in design time on the form.

    Now I want to create several image controls in runtime

  4. #4
    Guest

    Post

    Rename the image control as image1(0).

    To create a control array of the above control add this code:

    For ctr = 1 To 10
    load image1(ctr)
    Next ctr

  5. #5
    Addicted Member
    Join Date
    Jan 1999
    Location
    Sydney,NSW,Australia
    Posts
    178

    Post

    Apparently in vb6 you don't even have to include an intial control on your form. Haven't tried this yet, but my current project will require it :0

  6. #6
    Addicted Member
    Join Date
    Jan 1999
    Location
    Sydney,NSW,Australia
    Posts
    178

    Post

    Apparently in vb6 you don't even have to include an intial control on your form. Haven't tried this yet, but my current project will require it :0

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    38

    Post

    I'm working in VBA !!

    When I copy & paste the image control on my form, I'm not asked if I want to create a cotrol array (like VB does).

    How do I create a control array then ??
    (Damned, that VBA stuff sucks !)

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    38

    Post

    I found the following article on http://msdn.microsoft.com/library/pe...99/seside1.htm about control arrays etc.


    ------------------------------------------------------------------------------------------------------------------------------
    VBA UserForms aren't the same as VB forms (Ruby Forms). In fact, VBA UserForms are instances of an ActiveX Designer provided by Microsoft Forms 2.0 (FM20.dll), installed by both VBA and VB. MSForms and its controls are true ActiveX controls, whereas Ruby Forms and its controls are not. That means that MSForms and its controls support IDispatch. MSForms make no distinction between an external ActiveX control, such as third-party controls, and its own CommandButton. Unlike Ruby Forms, you can host MSForms in any application capable of hosting an ActiveX Designer. Also, you can copy controls from MSForms to Ruby Forms, but not the other way around.

    MSForms are robust ActiveX containers, but because they're more generic than Ruby Forms there are a few significant differences. For example, quite a few Ruby controls aren't supported by VBA: Timer, FileListBox, PictureBox, DriveListBox, DirListBox, Menu, Shape, and Line. Of course, most of these controls are available through third-party ActiveX libraries that do work with MSForms. MSForms don't support control arrays, data binding, menus, property pages, or MDI implementations.
    ------------------------------------------------------------------------------------------------------------------------------


  9. #9

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    38

    Post

    Problem solved:


    dim imgCntrl as New Image
    Set imgCntrl = Me.Controls.Add("Forms.Image.1")

Posting Permissions

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



Click Here to Expand Forum to Full Width