Justin jant
Justin jant

Reputation: 75

How to apply decimal format to a Userform Textbox entry?

I want my Price Text Box to have decimal format so when a user types 1000000 it shows 1.000.000.

I tried the code below but it doesn't show the decimal format in Price Textbox.

Private Sub UserForm_Initialize()
    tbPrice.Text = Format(Number, "0.000")
End Sub

enter image description here

Upvotes: 0

Views: 1767

Answers (1)

stud3nt
stud3nt

Reputation: 2153

You are updating the value on ForUserForm_Initializem() which will only update once the User form is loaded for first time. So in order to update the value which user enters into the textbox, you have to use AfterUpdate()

Private Sub tbPrice_AfterUpdate()
    tbPrice.Text = Format(tbPrice.Text, "0.000")
End Sub

This function will called every time the user updates the value in the textbox - tbPrice

Upvotes: 1

Related Questions