Hi,
Can anyone help me on this problem.
I need to repeat the input if user click cancel or enter value not it selection criteria. Here is my VBA code but got error
![]()
Please Login or Register to view this content.
Hi,
Can anyone help me on this problem.
I need to repeat the input if user click cancel or enter value not it selection criteria. Here is my VBA code but got error
![]()
Please Login or Register to view this content.
If by cancel button you mean the X on the top right hand of the form window I would just disable it with the code below and remove your 3rd if statement group from your code.
Place this in the userform vba window:
![]()
Please Login or Register to view this content.
Also note if you haven't already in some other portion of your coding will need an option for it to close on successful form completion.
Last edited by playaller; 05-23-2014 at 03:38 PM. Reason: Advised of closing form after compeltion
Shelton A.
If Helpful, Add Reputaion!
Hi playaller,
It means for both, (X) on the top right of the windows and also Cancel button in input box.
If user click either one or both, Application.Inputbox will appear until the user key in correct character.
If let say, the application request to input String (Y/N) but user enter number or symbols, the application still repeating until the correct character entered.
Regards,
Farid
A message box with two buttons would be a smother user interface
![]()
Please Login or Register to view this content.
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
Hi mikerickson,
Thanks for assist me.
It is much easier than Application.Inputbox.
Just to ask you what went wrong on my VBA code on the # post 1
Regards,
Farid
If you had to use your code you could have tried to leave the last condition open since it would default if the other 2 didn't happen anyways so you would exit the sub but not end it leaving the window open after the message box. As is it would just loop to the message box if the first to conditions were not met. If it still errord we would need to know which line gives the erorr.
sub data()
Dim NewStaff As Boolean
NewStaff = Application.InputBox("Is there any new staff to be updated?" & vbCrLf & vbCrLf & "Press Y, (Yes)" & vbCrLf & "Press N, (No)")
If NewStaff = "Y" Or NewStaff = "y" Then
Call XXXXXXXXX
ElseIf NewStaff = "N" Or NewStaff = "n" Then
Workbooks("workbookname").Close
ElseIf NewStaff = "" Then
MsgBox ("Please do not press cancel")
Exit Sub
End If
end sub
Last edited by playaller; 05-24-2014 at 02:12 AM.
Hi Playller,
Finally done. It works perfect.![]()
Anyway, thanks a lot.
![]()
Please Login or Register to view this content.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks