VBA Automaticly Update Label in User Form

RusheR

Board Regular
Joined
Feb 18, 2008
Messages
97
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
I have a text box for a user to insert a net price of an item, and underneath that text box I have a frame with 4 radio buttons in it to either add all taxes, no taxes, tax 1 or tax 2.<o:p></o:p>
<o:p></o:p>
I'd like to have a label beside the text box that shows the user the gross price based on what radio button is on and what they insert into the net price text box.<o:p></o:p>
<o:p></o:p>
My problem is, I want it to update automatically and it won't. I want the default option to have the "add all taxes" radio button on, so that as the user puts in their number, the label beside the net price text box updates.<o:p></o:p>
<o:p></o:p>
Does anyone know how to do this?

This is what I tried, but the price doesn't change,

Private Sub opnbtn_addgstandpst_Click()
If Me.opnbtn_addgstandpst.Value = True Then
Me.lbl_grossprice.Caption = "Gross Price: " & tb_Price.Value * 1.13
End If
End Sub
<o:p></o:p>
Thanks!<o:p></o:p>
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
The key piece I think you are missing is the me.repaint command. If you make a change to a userform control you need to instruct vba to redraw the screen or your changes will not appear.

To set the default to 'All Taxes' you just need to go into the properties of the 'AllTaxes' option button and set it's value as true

Here is a quick bit of code for a sample userform containing 1 textbox, 1 label, 1 frame and 4 option buttons that I've put together to do what you are asking if you need further guidance:


Code:
Private Sub TextBox1_Change()
If Opt_AllTaxes.Value Then
  Label1.Caption = TextBox1.Value + TextBox1.Value * 0.05
ElseIf Opt_NoTaxes.Value Then
  Label1.Caption = TextBox1.Value
ElseIf Opt_Tax2.Value Then
  Label1.Caption = TextBox1.Value + TextBox1.Value * 0.04
Else: Label1.Caption = TextBox1.Value + TextBox1.Value * 0.01
End If
Me.Repaint
End Sub
 
Private Sub Opt_AllTaxes_Click()
Label1.Caption = TextBox1.Value + TextBox1.Value * 0.05
Me.Repaint
End Sub
 
Private Sub Opt_NoTaxes_Click()
Label1.Caption = TextBox1.Value
Me.Repaint
End Sub
 
Private Sub Opt_Tax1_Click()
Label1.Caption = TextBox1.Value + TextBox1.Value * 0.04
Me.Repaint
End Sub
 
Private Sub Opt_Tax2_Click()
Label1.Caption = TextBox1.Value + TextBox1.Value * 0.01
Me.Repaint
End Sub

Take Care,

Owen
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,590
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top