Multiplying text box values - correct syntax

insomniac53

Board Regular
Joined
Sep 3, 2013
Messages
104
I'm trying 'simply' to multiply the contents of two text boxes and put the product in a third. This is the code I'm using:
Code:
Me.Controls.Item("TxtBox_A_Deposit").Value = format(CDbl(Me.Controls.Item("TxtBox_A_Percent").Value) * CInt(Me.Controls.Item("TxtBox_AB_Qty").Value), "£0")
but it throws up a Type Mismatch error, even though I'm forcing the data types to fit.
Can anyone tell me what I'm doing wrong?
Thanks.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
A textbox's value is a string, not a number. although your code looks like it takes that into account. Do the Percent and Qty textboxes also force units.
(i.e. put a pound sign or a percent sign in the cell).

try
Code:
Me.TxtBox_A_Deposit.Text = Format(Val(Me.TxtBox_A_Percent.Text) * Val(Me.TxtBox_AB_Qty.Text), "$0")
or
Me.TxtBox_A_Deposit.Text = Format(Val(Me.TxtBox_A_Percent.Text) / 100 * Val(Me.TxtBox_AB_Qty.Text), "$0")
 
Upvote 0
Thanks so much for that. Yes, it works. The "Val" method is one I haven't used before. I thought the "Cdbl" or "CInt" would work, but they didn't. The Percent and Qty textboxes also force units so I will use the same syntax. Again, many thanks. I didn't think I was going to get any sleep tonight.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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