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 May 20th, 2002, 01:47 PM   #1
rsimon36555
New Member
 
Join Date: Apr 2002
Location: Contractors Steel Company
Posts: 6
Default

I have two buttons on my userform with numerous textboxes. When I first run my userform, the buttons don't work on the first textbox. After I pass that box, the buttons work on all the other boxes. What gives? What makes that first textbox so special? It is setup that same as all the other textboxes.

Any help will be appreciated...Thanks!

_________________


[ This Message was edited by: rsimon36555 on 2002-05-20 12:48 ]
rsimon36555 is offline   Reply With Quote
Old May 20th, 2002, 02:18 PM   #2
Von Pookie
MrExcel MVP, Administrator
 
Von Pookie's Avatar
 
Join Date: Feb 2002
Location: The act or process of locating.
Posts: 13,679
Default

Could you post the code you are using for the userform?
Von Pookie is offline   Reply With Quote
Old May 20th, 2002, 06:26 PM   #3
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-05-20 12:47, rsimon36555 wrote:
I have two buttons on my userform with numerous textboxes. When I first run my userform, the buttons don't work on the first textbox. After I pass that box, the buttons work on all the other boxes. What gives? What makes that first textbox so special? It is setup that same as all the other textboxes.

Any help will be appreciated...Thanks!

_________________


[ This Message was edited by: rsimon36555 on 2002-05-20 12:48 ]
You may not have referenced the Text box properly.....what is your code ?
__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Old May 21st, 2002, 04:59 AM   #4
rsimon36555
New Member
 
Join Date: Apr 2002
Location: Contractors Steel Company
Posts: 6
Default

Here is the code. The starting textbox is ItemDescCode. It is here that neither button works. After I make an entry, and I'm in the next field, the buttons work.

Thanks for looking!



' Define Global Variables

Dim done As Boolean, ContinueRun As Boolean, SkipCost As Boolean
Dim LastRow As Integer, LastColumn As Integer, CurMLRow As Integer
Dim LivoniaTon As Integer, GrandRapidsTon As Integer, TwinsburgTon As Integer, BellevilleTon As Integer
Dim LivoniaPrice As Single, GrandRapidsPrice As Single, TwinsburgPrice As Single, BellevillePrice As Single
'****************************************************************************************
Public Function FindLastRow(SheetID As String) As Integer

With Sheets(SheetID)
FindLastRow = WorksheetFunction.CountA(.Columns(1))
End With

End Function
'****************************************************************************************
Public Function FindLastColumn(SheetID As String) As Integer

With Sheets(SheetID)
FindLastColumn = WorksheetFunction.CountA(.Rows(1))
End With

End Function
'****************************************************************************************
Private Sub CommandButton1_Click()
UserForm1.Hide
Unload UserForm1
Worksheets("masterlist").Select
ActiveWindow.WindowState = xlMaximized
End Sub

Private Sub CommandButton2_Click()
FinishProcess
End Sub
Private Sub FinishProcess()

Dim ctl As Control

Worksheets("masterlist").Cells(CurMLRow, 11) = LivoniaTon + GrandRapidsTon + TwinsburgTon + BellevilleTon
Worksheets("masterlist").Cells(CurMLRow, 11).NumberFormat = "###.00"

For Each ctl In UserForm1.Controls
If TypeName(ctl) = "TextBox" Then
If ctl.Name <> "ItemDescCode" Then ' We'll clear it when we get into the routine
ctl.Text = ""
End If
End If
Next ctl
End Sub
'****************************************************************************************
Private Sub ItemDescCode_Enter()

UserForm1.ItemDescCode.Value = ""
UserForm1.Prompt.Value = "Enter an item description"

End Sub
'****************************************************************************************
Private Sub ItemDescCode_AfterUpdate()

Dim ItemDescCode As String
Dim Rfound As Range, iLoop As Integer

ItemDescCode = UserForm1.ItemDescCode.Value

Set Rfound = Range("A1")
Set Rfound = Range(Cells(1, 1), Cells(LastRow, LastColumn)).Find(what:=ItemDescCode, after:=Rfound, lookat:=xlWhole, MatchCase:=False)

If Rfound Is Nothing Then
MsgBox "Item entered not found. Reenter your last item again."
ContinueRun = False
Else
If Rfound.Value = UCase$(ItemDescCode) Then
UserForm1.ItemForm.Value = Rfound.Offset(0, 1).Value
CurMLRow = FindLastRow("masterlist") + 1
Worksheets("masterlist").Cells(CurMLRow, 1).Value = Rfound.Value

Worksheets("MasterList").Cells(CurMLRow, 2).Value = Rfound.Offset(0, 1).Value
Columns(2).Select
Selection.Columns(2).Text
Columns(2).AutoFit

Cells(CurMLRow, 12).Text
Worksheets("MasterList").Cells(CurMLRow, 12).Value = Rfound.Offset(0, 2).Value
Columns(12).Select
Columns(12).AutoFit
' Worksheets("masterlist").Cells(CurMLRow, 12).NumberFormat = "####################"

ContinueRun = True
InitializeAllFields
Else
MsgBox "Item entered not found. Reenter your last item again."
ContinueRun = False
End If
End If

End Sub
'****************************************************************************************
Private Sub ItemDescCode_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If Not ContinueRun Then
Cancel = True
End If

End Sub
'****************************************************************************************
Sub InitializeAllFields()

LivoniaTon = 0
LivoniaPrice = 0
GrandRapidsTon = 0
GrandRapidsPrice = 0
TwinsburgTon = 0
TwinsburgPrice = 0
BellevilleTon = 0
BellevillePrice = 0

End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'****************************************************************************************
Private Sub LivoniaCost_enter()

UserForm1.Prompt.Value = "Enter the item purchase price (CWT)"

If LivoniaTon = 0 Then
' MsgBox "Moving on..."
UserForm1.GrandRapidsTons.SetFocus
End If

End Sub
'****************************************************************************************
Private Sub LivoniaCost_afterupdate()

If (IsNumeric(UserForm1.LivoniaCost.Value)) Then
LivoniaPrice = Val(UserForm1.LivoniaCost.Value)
UserForm1.LivoniaCost.Value = Format$(LivoniaPrice, "###.00")
Worksheets("masterlist").Cells(CurMLRow, 4) = LivoniaPrice
Worksheets("masterlist").Cells(CurMLRow, 4).NumberFormat = "###.00"
Else: MsgBox "Cost must be a numeric value"
ContinueRun = False
End If

End Sub
'****************************************************************************************
Private Sub LivoniaCost_Error(ByVal Number As Integer, ByVal Description As MSForms.ReturnString, ByVal SCode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, ByVal CancelDisplay As MSForms.ReturnBoolean)

If Not ContinueRun Then
Cancel = True
End If

End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'****************************************************************************************
Private Sub LivoniaTons_Enter()

UserForm1.Prompt.Value = "Enter the number of tons to order for Livonia"

End Sub
'****************************************************************************************
Private Sub LivoniaTons_AfterUpdate()

If (Len(UserForm1.LivoniaTons.Value) > 0) Then
If IsNumeric(UserForm1.LivoniaTons.Value) Then
LivoniaTon = Val(UserForm1.LivoniaTons.Value)

Select Case LivoniaTon
Case Is > 0
Worksheets("masterlist").Cells(CurMLRow, 3).Value = LivoniaTon
Worksheets("masterlist").Cells(CurMLRow, 3).NumberFormat = "####"
Case 0
UserForm1.GrandRapidsTons.SetFocus

Case Else
MsgBox "Enter only positive numbers or 0 (zero) as a value or leave blank"
ContinueRun = False
End Select
Else
MsgBox "Enter a number as a value or leave blank"
ContinueRun = False
End If
Else
UserForm1.GrandRapidsTons.SetFocus
End If

End Sub
'****************************************************************************************
Private Sub LivoniaTons_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If Not ContinueRun Then
Cancel = True
End If
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'****************************************************************************************
Private Sub GrandRapidsTons_Enter()

UserForm1.Prompt.Value = "Enter the number of tons to order for Grand Rapids"

End Sub
'****************************************************************************************
Private Sub GrandRapidsTons_AfterUpdate()

If (Len(UserForm1.GrandRapidsTons.Value) > 0) Then
If IsNumeric(UserForm1.GrandRapidsTons.Value) Then
GrandRapidsTon = Val(UserForm1.GrandRapidsTons.Value)

Select Case GrandRapidsTon
Case Is > 0
Worksheets("masterlist").Cells(CurMLRow, 5).Value = GrandRapidsTon
Worksheets("masterlist").Cells(CurMLRow, 5).NumberFormat = "####"

Case 0
UserForm1.TwinsburgTons.SetFocus

Case Else
MsgBox "Enter only positive numbers or 0 (zero) as a value or leave blank"
ContinueRun = False
End Select
Else
MsgBox "Enter a number as a value or leave blank"
ContinueRun = False
End If
Else
UserForm1.TwinsburgTons.SetFocus
End If

End Sub
'****************************************************************************************
Private Sub GrandRapidsTons_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If Not ContinueRun Then
Cancel = True
End If
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'****************************************************************************************
Private Sub GrandRapidsCost_enter()

UserForm1.Prompt.Value = "Enter the item purchase price (CWT)"

If GrandRapidsTon = 0 Then
' MsgBox "Moving on..."
UserForm1.TwinsburgTons.SetFocus
End If

End Sub
'****************************************************************************************
Private Sub GrandRapidsCost_afterupdate()

If (IsNumeric(UserForm1.GrandRapidsCost.Value)) Then
GrandRapidsPrice = Val(UserForm1.GrandRapidsCost.Value)
UserForm1.GrandRapidsCost.Value = Format$(GrandRapidsPrice, "###.00")
Worksheets("masterlist").Cells(CurMLRow, 6) = GrandRapidsPrice
Worksheets("masterlist").Cells(CurMLRow, 6).NumberFormat = "###.00"
Else
MsgBox "Cost must be a numeric value"
ContinueRun = False
End If

End Sub
'****************************************************************************************
Private Sub GrandRapidsCost_Error(ByVal Number As Integer, ByVal Description As MSForms.ReturnString, ByVal SCode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, ByVal CancelDisplay As MSForms.ReturnBoolean)

If Not ContinueRun Then
Cancel = True
End If

End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'****************************************************************************************
Private Sub TwinsburgTons_Enter()

UserForm1.Prompt.Value = "Enter the number of tons to order for Twinsburg"

End Sub
'****************************************************************************************
Private Sub TwinsburgTons_AfterUpdate()

If (Len(UserForm1.TwinsburgTons.Value) > 0) Then
If IsNumeric(UserForm1.TwinsburgTons.Value) Then
TwinsburgTon = Val(UserForm1.TwinsburgTons.Value)

Select Case TwinsburgTon
Case Is > 0
Worksheets("masterlist").Cells(CurMLRow, 7).Value = TwinsburgTon
Worksheets("masterlist").Cells(CurMLRow, 7).NumberFormat = "####"
Case 0
UserForm1.TwinsburgTons.SetFocus

Case Else
MsgBox "Enter only positive numbers or 0 (zero) as a value or leave blank"
ContinueRun = False
End Select
Else
MsgBox "Enter a number as a value or leave blank"
ContinueRun = False
End If
Else
UserForm1.TwinsburgTons.SetFocus
End If

End Sub
'****************************************************************************************
Private Sub TwinsburgTons_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If Not ContinueRun Then
Cancel = True
End If
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'****************************************************************************************
Private Sub TwinsburgCost_enter()

UserForm1.Prompt.Value = "Enter the item purchase price (CWT)"

If TwinsburgTon = 0 Then
' MsgBox "Moving on..."
UserForm1.BellevilleTons.SetFocus
End If

End Sub
'****************************************************************************************
Private Sub TwinsburgCost_afterupdate()

If (IsNumeric(UserForm1.TwinsburgCost.Value)) Then
TwinsburgPrice = Val(UserForm1.TwinsburgCost.Value)
UserForm1.TwinsburgCost.Value = Format$(TwinsburgPrice, "###.00")
Worksheets("masterlist").Cells(CurMLRow, = TwinsburgPrice
Worksheets("masterlist").Cells(CurMLRow, .NumberFormat = "###.00"
Else
MsgBox "Cost must be a numeric value"
ContinueRun = False
End If

End Sub
'****************************************************************************************
Private Sub TwinsburgCost_Error(ByVal Number As Integer, ByVal Description As MSForms.ReturnString, ByVal SCode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, ByVal CancelDisplay As MSForms.ReturnBoolean)

If Not ContinueRun Then
Cancel = True
End If

End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'****************************************************************************************
Private Sub BellevilleCost_enter()

UserForm1.Prompt.Value = "Enter the item purchase price (CWT)"

If BellevilleTon = 0 Then
' MsgBox "Moving on..."
' UserForm1.CommandButton2.SetFocus
FinishProcess
End If

End Sub
'****************************************************************************************
Private Sub BellevilleCost_afterupdate()

If (IsNumeric(UserForm1.BellevilleCost.Value)) Then
BellevillePrice = Val(UserForm1.BellevilleCost.Value)
UserForm1.BellevilleCost.Value = Format$(BellevillePrice, "###.00")
Worksheets("masterlist").Cells(CurMLRow, 10) = BellevillePrice
Worksheets("masterlist").Cells(CurMLRow, 10).NumberFormat = "###.00"
FinishProcess
Else: MsgBox "Cost must be a numeric value"
ContinueRun = False
End If

End Sub
'****************************************************************************************
Private Sub BellevilleCost_Error(ByVal Number As Integer, ByVal Description As MSForms.ReturnString, ByVal SCode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, ByVal CancelDisplay As MSForms.ReturnBoolean)

If Not ContinueRun Then
Cancel = True
End If

End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'****************************************************************************************
Private Sub BellevilleTons_Enter()

UserForm1.Prompt.Value = "Enter the number of tons to order for Belleville"

End Sub
'****************************************************************************************
Private Sub BellevilleTons_AfterUpdate()

If (Len(UserForm1.BellevilleTons.Value) > 0) Then
If IsNumeric(UserForm1.BellevilleTons.Value) Then
BellevilleTon = Val(UserForm1.BellevilleTons.Value)

Select Case BellevilleTon
Case Is > 0
Worksheets("masterlist").Cells(CurMLRow, 9).Value = BellevilleTon
Worksheets("masterlist").Cells(CurMLRow, 9).NumberFormat = "####"

Case 0
FinishProcess
' UserForm1.CommandButton2.SetFocus

Case Else
MsgBox "Enter only positive numbers or 0 (zero) as a value or leave blank"
ContinueRun = False
End Select
Else
MsgBox "Enter a number as a value or leave blank"
ContinueRun = False
End If
Else
' UserForm1.CommandButton2.SetFocus
FinishProcess
End If

End Sub
'****************************************************************************************
Private Sub BellevilleTons_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If Not ContinueRun Then
Cancel = True
End If

End Sub

Private Sub UserForm_Activate()

Dim itemsheet As String

itemsheet = Worksheets("ItemList").Name
Worksheets(itemsheet).Select
ActiveWindow.WindowState = xlMinimized

LastRow = FindLastRow(itemsheet)
LastColumn = FindLastColumn(itemsheet)

End Sub

Private Sub UserForm_Deactivate()

Worksheets("masterlist").Select
ActiveWindow.WindowState = xlMaximized

End Sub

rsimon36555 is offline   Reply With Quote
Old May 21st, 2002, 06:00 AM   #5
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Hi Robert...which textbox is not functioning.
From your discription I'm assuming that
@ the press of commandbutton2 your textbox
(which one) does not update ??
please elaborate.
__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Old May 21st, 2002, 07:04 AM   #6
rsimon36555
New Member
 
Join Date: Apr 2002
Location: Contractors Steel Company
Posts: 6
Default

The textbox is ItemDescCode (1st textbox). Neither button works. After leaving this textbox, both buttons work.

After further debugging, it appears that when I'm in the ItemDescCode textbox, when I hit one of the buttons, the routine immediately goes to the _exit routine where it is cycled back to the originating routine (like it never left and did anything).

What the question is now is: How can I tell what button was pressed from inside the _exit routine? I could then take the appropiate action from there.
_________________
Robert Simon
Contractors Steel Company
Novice VBA Programmer

[ This Message was edited by: rsimon36555 on 2002-05-21 13:10 ]
rsimon36555 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 06:27 AM.


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