MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 1st, 2002, 01:27 PM   #1
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

Hi everyone, yet another userform question.

I have a label in my form which is updated when a value is changed in a certain textbox. To do this, i use the textbox_BeforeUpdate (doing this calls a function to calculate a payment). But I'm having a problem. When I initialize the textbox in Userform_Initialize, it tries to do the BeforeUpdate process also. this is a problem because not all the variables have been defined in the initialization.

My question is: Is there a way to disable things such as BeforeUpdate when executing Userform_Initialize so that I can properly get all my variables defined?

Thanks
robfo0 is offline   Reply With Quote
Old Apr 1st, 2002, 01:35 PM   #2
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Hi,

What's your code? I tried to duplicate what you said but the Before_Update event didn't fire when I placed some code to change the textbox in the form's initialise event.

Dan.
dk is offline   Reply With Quote
Old Apr 1st, 2002, 01:41 PM   #3
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

Here is the whole code Im using. I'm trying to do the opposite of you, i DONT want the beforeupdate (actually the Change event) to execute until after the initialize userform is DONE. Anyway, here it is :

Private Sub UserForm_Initialize()

BORR_NAME = "BORR"
COBORR_NAME = "COBORR"
CONTRACTOR = "CONTRACTOR"
TYPE_IMPROV = "WINDOWS"
DOWN_PMT = 0
FIRST_TERM = 120

If FIRST_TERM.Value > 61 Then
FIRST_RECFEE = "$30.00"
Else
FIRST_RECFEE = "$20.00"
End If

FIRST_RATE.Value = Format(Worksheets("Sheet1").Range("RATE"), "0.00%")
AMT_FINAN = Format(Worksheets("Sheet1").Range("TESTVALUE").Value + FIRST_RECFEE, "$#,##0.00")
FIRST_DAYSDEF = InputBox("days def")


Call CALC_PAYMENT

End Sub


Private Sub FIRST_DAYSDEF_Change()
If FIRST_DAYSDEF = "" Then
FIRST_DAYSDEF = 0
Else
End If
Call CALC_PAYMENT
End Sub


Private Sub FIRST_RECFEE_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
FIRST_RECFEE = Format(FIRST_RECFEE, "$#,##0.00")
End Sub

Private Sub FIRST_RECFEE_Change()
If FIRST_RECFEE = "" Then
FIRST_RECFEE = 0
Else
Call CALC_AMT_FINAN
End If
Call CALC_PAYMENT
End Sub

Function CALC_PAYMENT()
If FIRST_DAYSDEF = 0 Then
FIRST_NEW_PMT = Format(Pmt(Worksheets("Sheet1").Range("RATE") / 12, FIRST_TERM, -AMT_FINAN), "$#,##0.00")
Else
FIRST_NEW_PMT = Format(AMT_FINAN * ((Pmt(Worksheets("Sheet1").Range("RATE") / 12, FIRST_TERM, -100) / 100) + (Worksheets("Sheet1").Range("RATE") / 365) * (FIRST_DAYSDEF / FIRST_TERM)), "$#,##0.00")
End If
End Function

Function CALC_AMT_FINAN()
AMT_FINAN = Format(Worksheets("Sheet1").Range("TESTVALUE") + FIRST_RECFEE, "$#,##0.00")
End Function

So whats happening is CALC_PAYMENT is getting called before FIRST_DAYSDEF is defined and its causing problems Help! thanks!
robfo0 is offline   Reply With Quote
Old Apr 1st, 2002, 02:11 PM   #4
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Hi,

I'm still not entirely sure if I understand the problem. There are problems in that you're changing the format of the textbox to "$#,##0.00" (effectively making the value of FIRST_RECFEE a string, not number) and then trying to perform a numerical calculation on it:-

AMT_FINAN = Format(Worksheets("Sheet1").Range("TESTVALUE") + FIRST_RECFEE, "$#,##0.00")

This is giving you a type mismatch error yes?

You could replace it with this line which converts FIRST_RECFEE to a numerical value.

AMT_FINAN = Format(Worksheets("Sheet1").Range("TESTVALUE") + Replace(FIRST_RECFEE, "$", "") * 1, "$#,##0.00")

I've got the format of your userform on my machine now so if this isn't the problem please post back and I'll have another look.

Regards,
Dan
dk is offline   Reply With Quote
Old Apr 1st, 2002, 02:14 PM   #5
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Also, you're going to get problems doing this:-

FIRST_RECFEE = "$30.00"

FIRST_RECFEE value is now a string and you'll have to convert it before you can carry out any calculations using it. I understand that you want the textboxes to be formatted but you'll have to convert the values before you can do anything with them.

Regards,
Dan
dk is offline   Reply With Quote
Old Apr 1st, 2002, 03:20 PM   #6
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

Dan,

Thanks for the response. Actually, you answered one of my previous posts. I thought formatting the formula simply changed the look, i didnt know it changed it to a string. That answers a lot of questions.

But I still have this problem. Whats happening is that im trying to initialize all my values in the Initialize Userform. In addition, i have calculations that execute on change and also beforeupdate so the form is always correct when the user changes values. The problem im running into is that when i initialize a variable, for example;

If i define FIRST_RECFEE first, it puts in the value, but then doing this causes the Change event to trigger (which contains a reference to the function CALC_PAYMENT, which contains the variable FIRST_DAYSDEF). But the variable FIRST_DAYSDEF has nothing in it because it hasnt been defined yet because it was interrupted by the Change event. So, my first idea was to prevent the Change or Beforeupdate Events from triggering while initializing so that this problem doesnt occur.

Get what I'm saying?

If you had another idea, im totally open to suggestions

Thanks again
robfo0 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 04:31 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes