Multiply Contents Of Text Box By Contents Of Label

Scythed

Registered User.
Local time
Today, 10:38
Joined
Aug 30, 2008
Messages
28
Hi, what I am trying to accomplish is to multiply the contents of a label by the contents of a textbox. Eg. The label is a static number that shows the cost of an item and the textbox is a variable that you can change to the amount that you would buy. I want to be able to find the total cost of the number of items you select. Any help would be appreciated, thank you very much.
 
Code:
msgbox CDbl(Me.LabelName.Caption) * CDbl(Nz(Me.TextBoxName.Value, 0))

Regards,
Tim
 
You really should use textboxes instead of a label as it will work much better. You can format the text box to LOOK like a label and, if you set the LOCKED (True) and ENABLED (FALSE) properties it will even be like a label where you can't click in it but it will show (as long as the locked is set as well as the enabled property it won't gray out like if you just used the enabled property).
 
What are the advantages of using a textbox instead and how would you modify the code to accomodate it for a textbox instead of a label? Also, Do you know how I can alter that code provided by pono so that it places the value into the label instead of making it appear in a popup? Thank you.
 
What are the advantages of using a textbox instead and how would you modify the code to accomodate it for a textbox instead of a label?

A text box has a value whereas a label does not. So it just makes sense to me to work with the same type of controls instead of referencing a caption. But, it is really up to you.

The calculation would just be

=[YourTextBoxName1] * [YourTextBoxName2]
 
When I try it using a text box it gives me a result of 0. This is the code I used, same as yours except adapted for my textbox names. Also, do you know how to set the contents of a text box to nothing or null? I want to make it so all of my text boxes, labels, combo boxes etc are empty when I open the form. Thank you.

Private Sub CalculatePrice_Click()
TotalPriceText = LengthNeededText * PriceText
End Sub
 

Users who are viewing this thread

Back
Top Bottom