Type Mismatch Error

conton

New Member
Joined
May 25, 2011
Messages
15
Hi there!

I get a the Type Mismatch runtime error when the following code runs in Access:

Code:
Me.Textbox1 = Me.Textbox2 * 136.4 - (Me.Textbox2 * 136.4 * Me.Textbox3)

The textboxes are formatted as follows:

Me.Textbox1 = Currency
Me.Textbox2 = General Number
Me.Textbox3 = Percent

So I assume the problem is that my equation is multiplying a general number with a percentage and Access isn't converting the percentage into number form (eg. 15% = 0.15).

Any ideas on how I can make this work?

Thanks in advance!
 
I re-created the layout, and this code works for me:
Code:
Private Sub Form_Current()
    Me.TextBox1.Value = Me.Textbox2.Value * 136.4 - (Me.Textbox2.Value * 136.4 * Me.TextBox3.Value)
End Sub

Thanks for looking into it!

I'm still getting the type mismatch error after adding .value to all the textboxes.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
It sounds like they may not be formatted correctly.

You say that they are "bound" text boxes.
How are the fields they are bound to formatted? Are any text?

Also, how were these textboxes added to your form?
If they are bound, the best way to do it is to display your field list and drag the field to the form. That way, you are sure that the text boxes will inherit all the properties of the fields that they are bound to.
 
Upvote 0
It sounds like they may not be formatted correctly.

You say that they are "bound" text boxes.
How are the fields they are bound to formatted? Are any text?

Also, how were these textboxes added to your form?
If they are bound, the best way to do it is to display your field list and drag the field to the form. That way, you are sure that the text boxes will inherit all the properties of the fields that they are bound to.

I'm pretty sure all the textboxes are bound correctly.

The Textbox1 field is bound to Currency
The Textbox2 field is bound to Number
The Textbox3 field is bound to Text

I've tried having the Textbox3 field bound to Number, but the percentage just changed to zero.
 
Upvote 0
I will let Joe give the final answer, but I am thinking the problem is coming from textbox3. how can you divide/multiply/add/subtract text from a number? Try wrapping textbox3 with the CInt() like:
Code:
 CInt(Me.Textbox3.Value)

Of course, if there is text in there, this will still cause a problem. May be best to make sure that the field that textbox3 is bound to is a number field.
 
Upvote 0
I'm pretty sure all the textboxes are bound correctly.

The Textbox1 field is bound to Currency
The Textbox2 field is bound to Number
The Textbox3 field is bound to Text
I think you are confusing terminology. What you are talking about is formatting. "Bound" means that the textbox is attached to a field in a table (or query) somewhere. See here: http://office.microsoft.com/en-us/access-help/create-a-text-box-HP005187740.aspx

If your textboxes are indeed bound, there will be a value in the Control Source (in the Properties of that textbox) that ties it back to a field in a table or query.

So are they really bound?
 
Upvote 0
I will let Joe give the final answer, but I am thinking the problem is coming from textbox3. how can you divide/multiply/add/subtract text from a number? Try wrapping textbox3 with the CInt() like:
Code:
 CInt(Me.Textbox3.Value)

Of course, if there is text in there, this will still cause a problem. May be best to make sure that the field that textbox3 is bound to is a number field.

But I need Textbox3 to be recognized as a decimal (eg. 15% = 0.15). Aren't integers whole numbers only?
 
Upvote 0
how can you divide/multiply/add/subtract text from a number?
I am not sure I understand where text comes into the equation. A percent should just be a number with percent formatting. If set-up properly, Access shouldn't identify that as text.
 
Upvote 0
I am not sure I understand where text comes into the equation.

I was referencing where conton said that textbox3 was "text" and was giving a rhetorical statement. I suppose I shall bow out of the discussion as I seem to be lending nothing more than a voice of confusion.

Sometimes I am a little to eager to help! ;)
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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