add numbers in textboxes on userform

K

KimberlyC

Hi!

I have textbox1, textbox2, textbox3, textbox4, and textbox5 on a userform.
I'm trying to add textbox1, textbox2, textbox3, and textbox4 and place the
sum (total) in Textbox5.
I've tried the following code attached to a command button:
me.textbox 5= (textbox1 + textbox2+ textbox3 + textbox4)

I keep getting the error message that textbox4 member or data cannot be
found. I've double check the spelling of the names and they are correct. If
I remove Textbox4 from the code, then the error states it cannot find
textbox3 member or data.

What am I doing wrong??

Thanks in advance for your help!!!

Kimberly
 
J

John Wilson

Kimberly,

What's in the textboxes is a string.
You have to convert them to numbers before adding them.

e.g.
me.textbox5= cDbl(textbox1) + cDbl(textbox2)
etc.

John
 
K

KimberlyC

Hi
Thanks!
I tried it and I'm still getting the same error messages.
Is there anything else that could casue these errors?

Thanks again!!
 
J

John Wilson

Kimberly,

If the textboxes do exist, they should be listed in the dropdown
in the VBA Editor.
If they don't, try to compile the project and save, close, reopen
the workbook.


John
 
J

John Wilson

Kimberly,
I just needed to close and reopen. It's working now.
I'm glad that solved your problem, but..........
When you add a textbox (or other control) to a UserForm
it should "automatically" be included in your "project" without
having to close and reopen.
Sometimes this doesn't happen and I can't give you an answer
as to why. I've asked why in the ng's and can't really get
a definitive answer myself, but it does happen.
Anyway.....since this did occur in the particular workbook
that you're using, if you haven't already done so, do yourself
a favor and dowload Rob Bovey's "Code Cleaner".
http://www.appspro.com/
and use it religiously (at least on this workbook).

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top