Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Goto "Start of Sub"
Hi.
I have a button on my excel sheet that call a macro (sub). Both in the middle and in the end of the sub a userform emerge where the user can choose if he want to continue or start at the beginning of the sub. My question is: Is there a command (code) (like Goto??) to go back to the beginning of the sub? How should i write a code that check if a txtbox on a userform is empty, and if it is a msgbox emerge. If the user click OK on the msgbox he will get a second (or more) chance to write in the txtbox! Any suggestion? -- Nil Satis Nisi Optimum |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Goto "Start of Sub"
Michael,
I think you are getting a bit confused on how objects work. A textbox is an object, and there are various events associated with it. You can only hand control to your code by trapping one of these events. Once you have completed your action (reaction) to the event), you exit and your code hands back to the system that will allow any other object on the userform to be acted upon. So what I am saying is you should either test on the textbox exit if it is empty and then force the user back in, or (preferably IMO), have some sort of commit button (usually called OK) which when clicked you check that all is okay. If so, don't let them finish, but force them back to the error. And of course you have a Quit button so that they can quit complete or not. -- HTH RP (remove nothere from the email address if mailing direct) "Michael" wrote in message ... Hi. I have a button on my excel sheet that call a macro (sub). Both in the middle and in the end of the sub a userform emerge where the user can choose if he want to continue or start at the beginning of the sub. My question is: Is there a command (code) (like Goto??) to go back to the beginning of the sub? How should i write a code that check if a txtbox on a userform is empty, and if it is a msgbox emerge. If the user click OK on the msgbox he will get a second (or more) chance to write in the txtbox! Any suggestion? -- Nil Satis Nisi Optimum |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Goto "Start of Sub"
Hi Bob.
Thanks! I have code that check the input in the txtbox on the userform, and return that to a range in the sheet, but if the input in the txtbox is out of range (ex. less than 0) a msgbox emerge and tell the user its out of range. I want to use a error handler in the code that "start again". My point is; if the input is out of range and the user click Ok on the msgbox he will get a second chance. -- Nil Satis Nisi Optimum "Bob Phillips" wrote: Michael, I think you are getting a bit confused on how objects work. A textbox is an object, and there are various events associated with it. You can only hand control to your code by trapping one of these events. Once you have completed your action (reaction) to the event), you exit and your code hands back to the system that will allow any other object on the userform to be acted upon. So what I am saying is you should either test on the textbox exit if it is empty and then force the user back in, or (preferably IMO), have some sort of commit button (usually called OK) which when clicked you check that all is okay. If so, don't let them finish, but force them back to the error. And of course you have a Quit button so that they can quit complete or not. -- HTH RP (remove nothere from the email address if mailing direct) "Michael" wrote in message ... Hi. I have a button on my excel sheet that call a macro (sub). Both in the middle and in the end of the sub a userform emerge where the user can choose if he want to continue or start at the beginning of the sub. My question is: Is there a command (code) (like Goto??) to go back to the beginning of the sub? How should i write a code that check if a txtbox on a userform is empty, and if it is a msgbox emerge. If the user click OK on the msgbox he will get a second (or more) chance to write in the txtbox! Any suggestion? -- Nil Satis Nisi Optimum |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Goto "Start of Sub"
Michael,
I would still use a button with code like Private Sub CommandButton1_Click() Dim ans With Me.TextBox1 If CDbl(.Text) < 0 Then ans = MsgBox("Invalid Amount, try again", vbOKCancel) If ans = vbOK Then .SelStart = 0 .SelLength = Len(.Text) .SetFocus End If Else Worksheets("Sheet1").Range("A1").Value = .Text End If End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Michael" wrote in message ... Hi Bob. Thanks! I have code that check the input in the txtbox on the userform, and return that to a range in the sheet, but if the input in the txtbox is out of range (ex. less than 0) a msgbox emerge and tell the user its out of range. I want to use a error handler in the code that "start again". My point is; if the input is out of range and the user click Ok on the msgbox he will get a second chance. -- Nil Satis Nisi Optimum "Bob Phillips" wrote: Michael, I think you are getting a bit confused on how objects work. A textbox is an object, and there are various events associated with it. You can only hand control to your code by trapping one of these events. Once you have completed your action (reaction) to the event), you exit and your code hands back to the system that will allow any other object on the userform to be acted upon. So what I am saying is you should either test on the textbox exit if it is empty and then force the user back in, or (preferably IMO), have some sort of commit button (usually called OK) which when clicked you check that all is okay. If so, don't let them finish, but force them back to the error. And of course you have a Quit button so that they can quit complete or not. -- HTH RP (remove nothere from the email address if mailing direct) "Michael" wrote in message ... Hi. I have a button on my excel sheet that call a macro (sub). Both in the middle and in the end of the sub a userform emerge where the user can choose if he want to continue or start at the beginning of the sub. My question is: Is there a command (code) (like Goto??) to go back to the beginning of the sub? How should i write a code that check if a txtbox on a userform is empty, and if it is a msgbox emerge. If the user click OK on the msgbox he will get a second (or more) chance to write in the txtbox! Any suggestion? -- Nil Satis Nisi Optimum |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to get cursor to start with "Find What i/o "Repalce With"? | Excel Discussion (Misc queries) | |||
set up macro to goto cell with "today" in | Excel Worksheet Functions | |||
HOW IS COLUMN "K" REFERENCED ON THE CURRENT ROW IN THE GOTO COMMAN | Excel Discussion (Misc queries) | |||
Question on "On Error GoTo skip" | Excel Discussion (Misc queries) |