PC Review


Reply
Thread Tools Rate Thread

Case Statment in Err trapping

 
 
lwm
Guest
Posts: n/a
 
      27th Jan 2008
I am having trouble with the code in 2:

when I add this code:
ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2

I get an errror:

Case Else outside Select Case

When I remark out the Case Else I get the error:

End Select without Select Case

What is wron g with the code.

The statement that appears to be causing the problem

ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2


Is giving the user a choice of continuing or quiting.

Thank you for your help and hopefully I have provided enough detail.



Badinput:
Select Case Erl
Case Is = 1
Msg = "Error! " & Esp & "You must Enter numbers between " & TabMin & Esp
& TabMax & _
vbCr & vbCr & " rerun Macro"
MsgBox Buttons:=vbCritical, prompt:=Msg

MsgBox "Ending program now"
Application.StatusBar = False
Application.ScreenUpdating = True

Case Is = 2
Msg = "Error! " & Esp & "Dublicate Tab name " & Esp & NewSheet & _
vbCr & vbCr & " Enter a unique Tab name"
' MsgBox prompt:=Msg, Buttons:=vbCritical
ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2

Case Else
Msg = "ending program"
MsgBox Msg
Exit Sub

End Select
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      27th Jan 2008
On 27 Jan., 23:10, lwm <l...@discussions.microsoft.com> wrote:
> I am having trouble with the code in 2:
>
> when I add this code:
> ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
> * * * * * * * * * If ResPonse = vbNo Then
> * * * * * * * * * * *Exit Sub
>
> * * * * * * * * * Else
> * * * * * * * * * * *GoTo 2
>
> I get an *errror:
>
> Case Else outside Select Case
>
> When I remark out the Case Else I get the error:
>
> End Select without Select Case
>
> What is wron g with the code.
>
> The statement that appears to be causing the problem
>
> *ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
> * * * * * * * * * If ResPonse = vbNo Then
> * * * * * * * * * * *Exit Sub
>
> * * * * * * * * * Else
> * * * * * * * * * * *GoTo 2
>
> Is giving the user a choice of continuing or quiting.
>
> Thank you for your help and hopefully I have provided enough detail.
>
> Badinput:
> * Select Case Erl
> * * Case Is = 1
> * * Msg = "Error! " & Esp & "You must Enter numbers between " & TabMin & Esp
> & TabMax & _
> * * * * * * * *vbCr & vbCr & " rerun Macro"
> * * * * * * * MsgBox Buttons:=vbCritical, prompt:=Msg
>
> * * * * * * * MsgBox "Ending program now"
> * * * * * * * Application.StatusBar = False
> * * * * * * * Application.ScreenUpdating = True
>
> * * Case Is = 2
> * * * Msg = "Error! " & Esp & "Dublicate Tab name " & Esp & NewSheet & _
> * * * * * * * *vbCr & vbCr & " Enter a unique Tab name"
> * * * * * * * *' MsgBox prompt:=Msg, Buttons:=vbCritical
> * * * * * * * ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
> * * * * * * * * * If ResPonse = vbNo Then
> * * * * * * * * * * *Exit Sub
>
> * * * * * * * * * Else
> * * * * * * * * * * *GoTo 2
>
> * Case Else
> * * Msg = "ending program"
> * * MsgBox Msg
> * * * Exit Sub
>
> * * End Select


Hi

You are missing "End If" before "Case Else"

Regards,

Per
 
Reply With Quote
 
lwm
Guest
Posts: n/a
 
      27th Jan 2008
My face is red with embracement.

Thank you.

"Per Jessen" wrote:

> On 27 Jan., 23:10, lwm <l...@discussions.microsoft.com> wrote:
> > I am having trouble with the code in 2:
> >
> > when I add this code:
> > ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
> > If ResPonse = vbNo Then
> > Exit Sub
> >
> > Else
> > GoTo 2
> >
> > I get an errror:
> >
> > Case Else outside Select Case
> >
> > When I remark out the Case Else I get the error:
> >
> > End Select without Select Case
> >
> > What is wron g with the code.
> >
> > The statement that appears to be causing the problem
> >
> > ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
> > If ResPonse = vbNo Then
> > Exit Sub
> >
> > Else
> > GoTo 2
> >
> > Is giving the user a choice of continuing or quiting.
> >
> > Thank you for your help and hopefully I have provided enough detail.
> >
> > Badinput:
> > Select Case Erl
> > Case Is = 1
> > Msg = "Error! " & Esp & "You must Enter numbers between " & TabMin & Esp
> > & TabMax & _
> > vbCr & vbCr & " rerun Macro"
> > MsgBox Buttons:=vbCritical, prompt:=Msg
> >
> > MsgBox "Ending program now"
> > Application.StatusBar = False
> > Application.ScreenUpdating = True
> >
> > Case Is = 2
> > Msg = "Error! " & Esp & "Dublicate Tab name " & Esp & NewSheet & _
> > vbCr & vbCr & " Enter a unique Tab name"
> > ' MsgBox prompt:=Msg, Buttons:=vbCritical
> > ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
> > If ResPonse = vbNo Then
> > Exit Sub
> >
> > Else
> > GoTo 2
> >
> > Case Else
> > Msg = "ending program"
> > MsgBox Msg
> > Exit Sub
> >
> > End Select

>
> Hi
>
> You are missing "End If" before "Case Else"
>
> Regards,
>
> Per
>

 
Reply With Quote
 
James
Guest
Posts: n/a
 
      27th Jan 2008
Hi lvm,

You need an End If statement immediately after Goto 2.

Cheers

James A.

"lwm" <(E-Mail Removed)> wrote in message
news952D948-CD34-4664-A380-(E-Mail Removed)...
> I am having trouble with the code in 2:
>
> when I add this code:
> ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
> If ResPonse = vbNo Then
> Exit Sub
>
> Else
> GoTo 2
>
> I get an errror:
>
> Case Else outside Select Case
>
> When I remark out the Case Else I get the error:
>
> End Select without Select Case
>
> What is wron g with the code.
>
> The statement that appears to be causing the problem
>
> ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
> If ResPonse = vbNo Then
> Exit Sub
>
> Else
> GoTo 2
>
>
> Is giving the user a choice of continuing or quiting.
>
> Thank you for your help and hopefully I have provided enough detail.
>
>
>
> Badinput:
> Select Case Erl
> Case Is = 1
> Msg = "Error! " & Esp & "You must Enter numbers between " & TabMin &
> Esp
> & TabMax & _
> vbCr & vbCr & " rerun Macro"
> MsgBox Buttons:=vbCritical, prompt:=Msg
>
> MsgBox "Ending program now"
> Application.StatusBar = False
> Application.ScreenUpdating = True
>
> Case Is = 2
> Msg = "Error! " & Esp & "Dublicate Tab name " & Esp & NewSheet & _
> vbCr & vbCr & " Enter a unique Tab name"
> ' MsgBox prompt:=Msg, Buttons:=vbCritical
> ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
> If ResPonse = vbNo Then
> Exit Sub
>
> Else
> GoTo 2
>
> Case Else
> Msg = "ending program"
> MsgBox Msg
> Exit Sub
>
> End Select


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if statment in case statement iccsi Microsoft Access Form Coding 2 21st Jan 2009 06:30 PM
IF STATMENT OR CASE STATEMENT =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Misc 1 10th Jan 2007 10:04 AM
Making a C++ like if statment case for excel in VBA =?Utf-8?B?SmltbXkgSG9mZmE=?= Microsoft Excel Programming 1 16th Aug 2005 08:21 PM
Should I use a Case or If Statment? =?Utf-8?B?bWVsd2VzdGVy?= Microsoft Access Database Table Design 3 23rd Jun 2005 03:26 PM
VBA Case Statment =?Utf-8?B?QnJlbm5hbg==?= Microsoft Access VBA Modules 6 31st Jan 2005 10:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:32 AM.