![]() |
Userform Initialize Problem !
Dear Sir, I have a Userform for the data entry purpose, when I press the OK button then records are written on the sheet, and one message is appearing YES/NO. if I press Yes, then Userform must be clear all fields. but at the same time message appearing "Please use numbers only" infact I put the restriction on the Unit Price field, that should be numbers only. then I dont understand why this message is coming when I press OK button. any suggession ??? I AM USING THE BELOW CODE ========================= Private Sub CommandButton3_Click() ' for ok button ActiveWorkbook.Sheets("DailyPurchase").Activate Range("A5").Select ' to fill up combo box for the category If ComboCategory.ListIndex = -1 Then MsgBox "You must choose the category SHAHZAD" ComboCategory.SetFocus Exit Sub End If ' to fill up Date If DatePurchase = "" Then MsgBox "you must provide date" DatePurchase.SetFocus Exit Sub End If ' to fill up QTY If txtQuantity = "" Then MsgBox " you must provide Quantity " txtQuantity.SetFocus Exit Sub End If ' to fill up Unit price If txtUnitPrice = "" Then MsgBox " you must provide Unit Price " txtUnitPrice.SetFocus Exit Sub End If Do If IsEmpty(ActiveCell) = False Then ActiveCell.Offset(1, 0).Select End If Loop Until IsEmpty(ActiveCell) = True ActiveCell.Value = DatePurchase.Value ActiveCell.Offset(0, 1) = TxtDescription.Value ActiveCell.Offset(0, 2) = txtQuantity.Value ActiveCell.Offset(0, 3) = txtUnitPrice.Value ActiveCell.Offset(0, 5) = ComboCategory.Value ActiveCell.Offset(0, 6) = txtPR.Value ActiveCell.Offset(0, 7) = txtRemarks.Value ' Range("A5").Select ' Ask and Do Procedure If MsgBox("One record is written, do you have more entries ?", vbYesNo, "Title") = vbYes Then Call UserForm_Initialize Else Unload Me End If End Sub Private Sub UserForm_Initialize() TxtDescription.Value = "" DatePurchase.Value = "" txtUnitPrice.Value = "" txtQuantity.Value = "" txtPR.Value = "" ComboCategory.Value = "" txtQuantity.Value = "" txtRemarks.Value = "" DatePurchase.SetFocus End Sub Private Sub txtUnitPrice_change() If Not IsNumeric(txtUnitPrice.Text) Then MsgBox "Please use numbers only" Exit Sub End If End Sub =================================== Please give me the solution, I dont need this message when I press OK button. Regards. Shahzad |
Userform Initialize Problem !
When you clear the cells they are causing an event to occur you must disable
these events Application.EnableEvents = False TxtDescription.Value = "" DatePurchase.Value = "" txtUnitPrice.Value = "" txtQuantity.Value = "" txtPR.Value = "" ComboCategory.Value = "" txtQuantity.Value = "" txtRemarks.Value = "" DatePurchase.SetFocus Application.EnableEvents = True " wrote: Dear Sir, I have a Userform for the data entry purpose, when I press the OK button then records are written on the sheet, and one message is appearing YES/NO. if I press Yes, then Userform must be clear all fields. but at the same time message appearing "Please use numbers only" infact I put the restriction on the Unit Price field, that should be numbers only. then I dont understand why this message is coming when I press OK button. any suggession ??? I AM USING THE BELOW CODE ========================= Private Sub CommandButton3_Click() ' for ok button ActiveWorkbook.Sheets("DailyPurchase").Activate Range("A5").Select ' to fill up combo box for the category If ComboCategory.ListIndex = -1 Then MsgBox "You must choose the category SHAHZAD" ComboCategory.SetFocus Exit Sub End If ' to fill up Date If DatePurchase = "" Then MsgBox "you must provide date" DatePurchase.SetFocus Exit Sub End If ' to fill up QTY If txtQuantity = "" Then MsgBox " you must provide Quantity " txtQuantity.SetFocus Exit Sub End If ' to fill up Unit price If txtUnitPrice = "" Then MsgBox " you must provide Unit Price " txtUnitPrice.SetFocus Exit Sub End If Do If IsEmpty(ActiveCell) = False Then ActiveCell.Offset(1, 0).Select End If Loop Until IsEmpty(ActiveCell) = True ActiveCell.Value = DatePurchase.Value ActiveCell.Offset(0, 1) = TxtDescription.Value ActiveCell.Offset(0, 2) = txtQuantity.Value ActiveCell.Offset(0, 3) = txtUnitPrice.Value ActiveCell.Offset(0, 5) = ComboCategory.Value ActiveCell.Offset(0, 6) = txtPR.Value ActiveCell.Offset(0, 7) = txtRemarks.Value ' Range("A5").Select ' Ask and Do Procedure If MsgBox("One record is written, do you have more entries ?", vbYesNo, "Title") = vbYes Then Call UserForm_Initialize Else Unload Me End If End Sub Private Sub UserForm_Initialize() TxtDescription.Value = "" DatePurchase.Value = "" txtUnitPrice.Value = "" txtQuantity.Value = "" txtPR.Value = "" ComboCategory.Value = "" txtQuantity.Value = "" txtRemarks.Value = "" DatePurchase.SetFocus End Sub Private Sub txtUnitPrice_change() If Not IsNumeric(txtUnitPrice.Text) Then MsgBox "Please use numbers only" Exit Sub End If End Sub =================================== Please give me the solution, I dont need this message when I press OK button. Regards. Shahzad |
All times are GMT +1. The time now is 06:08 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com