Re: user form fundamentals
Moved to Office Development
Re: user form fundamentals
Welcome to the Forums :wave:
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
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
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
Re: user form fundamentals
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
Re: user form fundamentals
Hi,
Write all "Build_All_Charts" macro code in "Private Sub Build_Button_Click()"
It will be so simple.
Re: user form fundamentals
Hello cssriraman,
I don't understand what you are telling me. Please give me some more details.
Thanks,
bkelly
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.
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.
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?
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?