Results 1 to 13 of 13

Thread: user form fundamentals

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    user form fundamentals

    I have two books and cannot find a simple example of a user form and how to get the data from a user form into the macro that calls the form. Will someone please give me an example? My suggested example is a user form with two check boxes (call them check1 and check2), a run button and a cancel button. I need the VBA code that will open the form and when the form is closed, the VBA code has the values of the four buttons available for use. It does not have to do anything, just be able to see the values in the locals window.

    Thanks for your time,
    bkelly

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: user form fundamentals

    Moved to Office Development

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: user form fundamentals

    Welcome to the Forums

    In the simplest example, add the userform to your VBA project from the VB Editor page. It's the second button up in the top-left of the screen.

    Once you've added the userform, you can display it using:

    VB Code:
    1. Userform1.Show

    If you have some textboxes on the userform, then you could do the following:

    At the top of your code, or in a separate module, put:

    VB Code:
    1. Public Textbox1Output as string
    2.  Public Textbox2Output as string

    In the Userform_Terminate event, put:

    VB Code:
    1. Textbox1Output = TextBox1.Text
    2.  Textbox2Output = TextBox2.Text


    and the values would be saved into these variables for future use. Does that give you an idea of how it works?

    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  4. #4
    Lively Member
    Join Date
    Nov 2005
    Posts
    68

    Re: user form fundamentals

    You dont need the globals

    in your macro module
    VB Code:
    1. Sub my_macro()
    2. UserForm1.Show
    3. Dim b As Boolean
    4. b = UserForm1.CheckBox1.Value
    5. MsgBox (b)
    6. End Sub
    in the form module
    VB Code:
    1. Private Sub CommandButton1_Click()
    2.     Me.Hide
    3. End Sub
    "bla, bla,... exists number M so for each n > M bla, bla..." Exists? Where is it? (Kronecker said...)

  5. #5
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: user form fundamentals

    ...but don't forget that this will only be valid as long as the userform is kept open. If you allow it to be closed, then you lose any information on it. So you'll need to prevent it from being closed, even with the red x, and Hide it instead.


    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: user form fundamentals

    Have a look here
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: user form fundamentals

    Hello DKenny

    I checked the link, good info there, keep working it. I appreciate your attitude towards writing good code. Its time people were more concerned about doing it right than just getting what appears to be good results.

    I continue to have some problems with my form. The form has three check boxes and two control boxes. The check boxes pick one or more charts to build, one control box to build the charts and one to exit without building. The calling function gets the values of the check boxes, but not the control boxes. Do you have a clue as to what I may have wrong?

    Thanks for your time.

    Functions from the form:

    Private Sub All_AGCs_Button_Click()
    End Sub

    Private Sub AZ_EL_AUTO_AGC_Button_Click()
    End Sub

    Private Sub AZ_EL_CMD_and_Modes_Button_Click()
    End Sub

    Private Sub Build_Button_Click()
    Me.Hide
    End Sub

    Private Sub Cancel_Button_Click()
    Me.Hide
    End Sub

    *******************************************
    Macro code follows:

    Sub Build_All_Charts()

    Chart_Build_Selector.Show

    Dim CBS_AZ_EL_AUTO_AGC_Button As Boolean
    Dim CBS_All_AGCs_Button As Boolean
    Dim CBS_AZ_EL_CMD_and_Modes_Button As Boolean
    Dim CBS_Cancel_Button As Boolean
    Dim CBS_Build_Button As Boolean

    CBS_AZ_EL_AUTO_AGC_Button = Chart_Build_Selector.AZ_EL_AUTO_AGC_Button
    CBS_All_AGCs_Button = Chart_Build_Selector.All_AGCs_Button
    CBS_AZ_EL_CMD_and_Modes_Button = Chart_Build_Selector.AZ_EL_CMD_and_Modes_Button
    CBS_Cancel_Button = Chart_Build_Selector.Cancel_Button
    CBS_Build_Button = Chart_Build_Selector.Build_Button


    If CBS_Cancel_Button = True Then
    Exit Sub
    End If

    If CBS_Build_Button = False Then
    Exit Sub
    End If

    If CBS_AZ_EL_AUTO_AGC_Button = True Then
    Call Chart_AZ_EL_AUTO_AGC
    End If

    If CBS_All_AGCs_Button = True Then
    Call Chart_AGC_all
    End If

    If CBS_AZ_EL_CMD_and_Modes_Button = True Then
    Call Chart_ViaSat_AZ_EL_CMD_AGC_MODE
    End If


    End Sub

  8. #8
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: user form fundamentals

    Hi,

    Write all "Build_All_Charts" macro code in "Private Sub Build_Button_Click()"

    It will be so simple.
    CS

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: user form fundamentals

    Hello cssriraman,
    I don't understand what you are telling me. Please give me some more details.

    Thanks,
    bkelly

  10. #10
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: user form fundamentals

    VB Code:
    1. Private Sub Build_Button_Click()
    2. If CBS_AZ_EL_AUTO_AGC_Button.Value = True Then
    3. Call Chart_AZ_EL_AUTO_AGC
    4. End If
    5.  
    6. If CBS_All_AGCs_Button.Value = True Then
    7. Call Chart_AGC_all
    8. End If
    9.  
    10. If CBS_AZ_EL_CMD_and_Modes_Button.Value = True Then
    11. Call Chart_ViaSat_AZ_EL_CMD_AGC_MODE
    12. End If
    13. End Sub
    What are these Options available to the user?

    What it will do?

    Please explain. So, I might give some more ideas.
    CS

  11. #11

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: user form fundamentals

    Hello CS,
    I am a systems engieer for a range safety system. Part of our system is a tracking antenna that follows a vehicle during launch. The ACU (Antenna Control Unit) logs its parameters and we analyze that data to check our performance. My utilities imports the data from the ACU, does some data massaging and synthesizes a few columns.

    The purpose of the macros is to produce charts showing the antenna system performance. The three calls I have chart various aspects of the antenna. The first one charts Azimuth angles, Elevation angels, autotrack error, and the AGC (Automatic Gain Control) of the tracking receiver. The second is the AGCs of all the receivers and the third includes some mode information. There are several more charts, but this is enough to get the concnept going.

    The check boxes select the charts to make. I get the True/False condition from those in my calling function. The control buttons provide the user the ability to say, make the charts now, or exit and don't many any charts. I do not get any information from the control buttons.

    What do I need to do to get the data from the control buttons.

  12. #12

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: user form fundamentals

    New Information. I have just read in newsgroup microsoft.public.office.developer.vba that the control buttons will always return false. In order to get that data, I must capture the event with a new variable and read it. I think this will resolve my problem. Any thoughts?

  13. #13
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: user form fundamentals

    Why do you need to get the data from the control buttons?

    Why do you need another function?

    Once the user clicked the build button, build the chart. before that, check all the option buttons whether they are true or false. that's it.

    Write the code in "Build_Button_Click" procedure as I mentioned in post #10.

    are you clear with that?
    CS

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