|
-
Mar 11th, 2006, 07:43 AM
#1
Thread Starter
New Member
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
-
Mar 11th, 2006, 08:27 AM
#2
Re: user form fundamentals
Moved to Office Development
-
Mar 11th, 2006, 09:40 AM
#3
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:
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:
Public Textbox1Output as string
Public Textbox2Output as string
In the Userform_Terminate event, put:
VB Code:
Textbox1Output = TextBox1.Text
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
-
Mar 11th, 2006, 09:46 AM
#4
Lively Member
Re: user form fundamentals
You dont need the globals
in your macro module
VB Code:
Sub my_macro()
UserForm1.Show
Dim b As Boolean
b = UserForm1.CheckBox1.Value
MsgBox (b)
End Sub
in the form module
VB Code:
Private Sub CommandButton1_Click()
Me.Hide
End Sub
"bla, bla,... exists number M so for each n > M bla, bla..." Exists? Where is it? (Kronecker said...)
-
Mar 11th, 2006, 09:52 AM
#5
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
-
Mar 11th, 2006, 11:13 AM
#6
Re: user form fundamentals
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 11th, 2006, 03:43 PM
#7
Thread Starter
New Member
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
-
Mar 11th, 2006, 09:03 PM
#8
Re: user form fundamentals
Hi,
Write all "Build_All_Charts" macro code in "Private Sub Build_Button_Click()"
It will be so simple.
-
Mar 11th, 2006, 09:23 PM
#9
Thread Starter
New Member
Re: user form fundamentals
Hello cssriraman,
I don't understand what you are telling me. Please give me some more details.
Thanks,
bkelly
-
Mar 11th, 2006, 09:34 PM
#10
Re: user form fundamentals
VB Code:
Private Sub Build_Button_Click()
If CBS_AZ_EL_AUTO_AGC_Button.Value = True Then
Call Chart_AZ_EL_AUTO_AGC
End If
If CBS_All_AGCs_Button.Value = True Then
Call Chart_AGC_all
End If
If CBS_AZ_EL_CMD_and_Modes_Button.Value = True Then
Call Chart_ViaSat_AZ_EL_CMD_AGC_MODE
End If
End Sub
What are these Options available to the user?
What it will do?
Please explain. So, I might give some more ideas.
-
Mar 12th, 2006, 07:43 AM
#11
Thread Starter
New Member
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.
-
Mar 12th, 2006, 05:12 PM
#12
Thread Starter
New Member
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?
-
Mar 13th, 2006, 11:50 AM
#13
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|