Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Sep 2002
    Location
    Detroit, Michigan, USA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Controls on forms (WD2000/VBA)

    I'm creating an application that includes a built-in user form. This form has native controls and at the same time, under normal operation, more controls (always txt boxes) are added to the form (in an array fashion). Now...gaining access to and operating with the native textoboxes is fine but, I am having a hard time operation with the newly created ones. Once the text boxes have been created, I need to input numerical data and operate with it upon cliking of one of the original controls (a button in this case). In what collection are the newly ones created?.

    Code is posted. Anybody feel free to copy...add a button to operate as follows:
    For example:
    txtPt(2)=txtFin(2)-txtSt(2)
    Not sure how to access the controls after entering data into the St and Fin fields.
    Thanks in advance.

    PS: Word file was renamed .doc for upload purposes. It's actually a *.dot

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

    Re: Controls on forms (WD2000/VBA)

    I don't understand what you are doing, but if you want to refer to the arrays of controls anywhere in the form module, you must declare them at the top, before all procedures and functions, and not in cmd1_Click:

    Option Explicit

    Public lineNum As Integer
    Dim txtSt(30) As TextBox, txtFin(30) As TextBox, txtPt(30) As TextBox, txtJob(30) As TextBox
    Dim txtType(30) As ComboBox


    Private Sub cbPG_Change()
    ...

  3. #3
    Star Lounger
    Join Date
    Sep 2002
    Location
    Detroit, Michigan, USA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Controls on forms (WD2000/VBA)

    What I am doing is mathematically operating with the data input in the programatically created fields. I did some tinkering and figured out that upon creating the fields with specific names (as opposed to to using the default names), the fields do respond to code but are not identifiable via the original array. That is..if I assigned a name St1 to a certain text field created via code, the code will recognize the field only with this name (as expected) and not as part of the original array ( not as expected). Also, interesting is that the textbox must be accessed by using the exclamation mark and not the dot (because the field was created at run time....as in frm!St1). Again, I still didn't figure out how to access the original array of controls if they are created programatically

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Controls on forms (WD2000/VBA)

    Controls in an array are recognized by their name/index combination. If you change the name, you remove the control from the array. How are you trying to address the controls? If you use frm!St(1), you should be able to reference the control in the array.
    Charlotte

  5. #5
    Star Lounger
    Join Date
    Sep 2002
    Location
    Detroit, Michigan, USA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Controls on forms (WD2000/VBA)

    Perhaps it should but.... . The array is supposed to be defined by the ..for example...Set txtJob(1)=......... part of the control creating routine. The name (argument at the end of the right part of the object setting line) being optional shouldn't have a great deal of importance. That is I should be able to operate mathematically with frm!txtFin(1)-frm!txtSt(1)..and yet....Oh well.... [img]/forums/images/smilies/wink.gif[/img]

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Controls on forms (WD2000/VBA)

    VBA for Office doesn't have control arrays the way VB6 has. txtFin(1), although it represents a control on the form, is just an array element, not a form element . You can calculate txtPt(1) = txtFin(1) - txtSt(1), but frm!txtPt(1) = frm!txtFin(1) - frm!txtSt(1) will raise an error, and that is logical within Office VBA.

Posting Permissions

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