Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a problem with a userform. This userform is shown when the user clicks
on a button in the excel spreadsheet. The user is then to enter some info in various fields in the userForm. However when the user submits erronous info the program gives a message in a message box to the user. when the user clicks the ok button the user shall return to the userform (preferably containing the same info as before). My problem is that I dont know how to retun to the userform. In the code for Sheet1 I have: Public Sub startKnapp_Click() userForm1.Show End Sub when the user clicks the button the userform is shown and it is possible to enter info. The check for error info (it works) is: Private Sub checkDate() If (Not (IsDate(userForm1.TextBox1.Text))) Then MsgBox ("Error") End If If (Not (IsDate(userForm1.TextBox2.Text))) Then MsgBox ("Error") End If End Sub however this sub is called when the user has enterd info and THEN PRESSES AN OK BUTTON. The code is: Private Sub genereraRapportKnapp_Click() Call checkDate Call mainProgram Unload Me End Sub How do I write the code so that the user returns to the form? I have tried calling the sub that shows the userform but it does not work (the program says that it is already shown..). If you know how to solve this problem or avoid it please help me! Any assistance is of value! |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Exit sub
(i.e as in--- Private Sub checkDate() If (Not (IsDate(userForm1.TextBox1.Text))) Then MsgBox ("Error") Exit Sub End If If (Not (IsDate(userForm1.TextBox2.Text))) Then MsgBox ("Error") Exit sub End If End Sub HTH Duncan I have a problem with a userform. This userform is shown when the user clicks on a button in the excel spreadsheet. The user is then to enter some info in various fields in the userForm. However when the user submits erronous info the program gives a message in a message box to the user. when the user clicks the ok button the user shall return to the userform (preferably containing the same info as before). My problem is that I dont know how to retun to the userform. In the code for Sheet1 I have: Public Sub startKnapp_Click() userForm1.Show End Sub when the user clicks the button the userform is shown and it is possible to enter info. The check for error info (it works) is: Private Sub checkDate() If (Not (IsDate(userForm1.TextBox1.Text))) Then MsgBox ("Error") End If If (Not (IsDate(userForm1.TextBox2.Text))) Then MsgBox ("Error") End If End Sub however this sub is called when the user has enterd info and THEN PRESSES AN OK BUTTON. The code is: Private Sub genereraRapportKnapp_Click() Call checkDate Call mainProgram Unload Me End Sub How do I write the code so that the user returns to the form? I have tried calling the sub that shows the userform but it does not work (the program says that it is already shown..). If you know how to solve this problem or avoid it please help me! Any assistance is of value! |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If it were me doing it (bearing in mind im much of a beginner myself) I
would put the action code behind the button click and then I could exit the sub (end the click and return to the form) if something was wrong on my check Duncan Fabrizio wrote: I have a problem with a userform. This userform is shown when the user clicks on a button in the excel spreadsheet. The user is then to enter some info in various fields in the userForm. However when the user submits erronous info the program gives a message in a message box to the user. when the user clicks the ok button the user shall return to the userform (preferably containing the same info as before). My problem is that I dont know how to retun to the userform. In the code for Sheet1 I have: Public Sub startKnapp_Click() userForm1.Show End Sub when the user clicks the button the userform is shown and it is possible to enter info. The check for error info (it works) is: Private Sub checkDate() If (Not (IsDate(userForm1.TextBox1.Text))) Then MsgBox ("Error") End If If (Not (IsDate(userForm1.TextBox2.Text))) Then MsgBox ("Error") End If End Sub however this sub is called when the user has enterd info and THEN PRESSES AN OK BUTTON. The code is: Private Sub genereraRapportKnapp_Click() Call checkDate Call mainProgram Unload Me End Sub How do I write the code so that the user returns to the form? I have tried calling the sub that shows the userform but it does not work (the program says that it is already shown..). If you know how to solve this problem or avoid it please help me! Any assistance is of value! |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Why not use the EXIT event of the textbox to do the validation, which
would stop them even getting to the button to close the form? Fabrizio wrote: I have a problem with a userform. This userform is shown when the user clicks on a button in the excel spreadsheet. The user is then to enter some info in various fields in the userForm. However when the user submits erronous info the program gives a message in a message box to the user. when the user clicks the ok button the user shall return to the userform (preferably containing the same info as before). My problem is that I dont know how to retun to the userform. In the code for Sheet1 I have: Public Sub startKnapp_Click() userForm1.Show End Sub when the user clicks the button the userform is shown and it is possible to enter info. The check for error info (it works) is: Private Sub checkDate() If (Not (IsDate(userForm1.TextBox1.Text))) Then MsgBox ("Error") End If If (Not (IsDate(userForm1.TextBox2.Text))) Then MsgBox ("Error") End If End Sub however this sub is called when the user has enterd info and THEN PRESSES AN OK BUTTON. The code is: Private Sub genereraRapportKnapp_Click() Call checkDate Call mainProgram Unload Me End Sub How do I write the code so that the user returns to the form? I have tried calling the sub that shows the userform but it does not work (the program says that it is already shown..). If you know how to solve this problem or avoid it please help me! Any assistance is of value! |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Maybe you can validate your entries before you get to the reporting step.
Something like: Option Explicit Private Sub CommandButton1_Click() MsgBox "Ok clicked" Unload Me End Sub Private Sub TextBox1_Change() Call IsEverythingValid End Sub Private Sub TextBox2_Change() Call IsEverythingValid End Sub Private Sub UserForm_Initialize() Me.CommandButton1.Enabled = False Me.Label1.Caption = "" End Sub Private Sub IsEverythingValid() Dim AllOk As Boolean AllOk = True If IsDate(Me.TextBox1.Value) = False Then AllOk = False Me.Label1.Caption = "Please Enter A Date In Textbox 1" Else If IsDate(Me.TextBox2.Value) = False Then AllOk = False Me.Label1.Caption = "Please Enter A Date In Textbox 2" End If End If If AllOk = True Then Me.Label1.Caption = "" End If Me.CommandButton1.Enabled = AllOk End Sub The button won't be enabled until there's something that looks like a date in each of those two checkboxes. And you could add other checks, too. Fabrizio wrote: I have a problem with a userform. This userform is shown when the user clicks on a button in the excel spreadsheet. The user is then to enter some info in various fields in the userForm. However when the user submits erronous info the program gives a message in a message box to the user. when the user clicks the ok button the user shall return to the userform (preferably containing the same info as before). My problem is that I dont know how to retun to the userform. In the code for Sheet1 I have: Public Sub startKnapp_Click() userForm1.Show End Sub when the user clicks the button the userform is shown and it is possible to enter info. The check for error info (it works) is: Private Sub checkDate() If (Not (IsDate(userForm1.TextBox1.Text))) Then MsgBox ("Error") End If If (Not (IsDate(userForm1.TextBox2.Text))) Then MsgBox ("Error") End If End Sub however this sub is called when the user has enterd info and THEN PRESSES AN OK BUTTON. The code is: Private Sub genereraRapportKnapp_Click() Call checkDate Call mainProgram Unload Me End Sub How do I write the code so that the user returns to the form? I have tried calling the sub that shows the userform but it does not work (the program says that it is already shown..). If you know how to solve this problem or avoid it please help me! Any assistance is of value! -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
MessageBox with tick box | Excel Discussion (Misc queries) | |||
Anything wrong with Messagebox API? | Excel Programming | |||
Printing messagebox | Excel Discussion (Misc queries) | |||
adding usr defined event procedure of textbox in usrform ?? | Excel Programming | |||
Working around a messagebox | Excel Programming |