Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 5th, 2005, 10:35 AM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to junaidraja30
Default Select Case

Basically I have three buttons which is liked to a calendar and these three buttons are linked to the textboxes...All i have to do is that enter this code... the code does work but there is a compile error saying SELECT CASE WITHOUT CASE

this is my code:

Private Sub cmdSet_Click()

    'Set date in source object
        Select Case GCalSource

        Case "date_on_call_1"
            Form_frmStaffDetails.date_on_call_1 = CalObject.Value
            If ((CalObject.Value = Form_frmStaffDetails.date_on_call_2) Or (CalObject.Value = Form_frmStaffDetails.date_on_call_3)) Then
                MsgBox ("Invalid Date! Doctor cannot be on call at same times.")
            Else
             If (CalObject.Value < date) Then
                    MsgBox ("Invalid Date! The doctor cannot be on call on a previous date.")
                Else
                    DoCmd.Close acForm, "FrmCalendar2"
             End If
        
     Case "date_on_call_2"
            Form_frmStaffDetails.date_on_call_2 = CalObject.Value
            If ((CalObject.Value = Form_frmStaffDetails.date_on_call_1) Or (CalObject.Value = Form_frmStaffDetails.date_on_call_3)) Then
                MsgBox ("Invalid Date! Doctor cannot be on call at same times.")
            Else
             If (CalObject.Value < date) Then
                 MsgBox ("Invalid Date! The doctor cannot be on call on a previous date.")
         Else
            DoCmd.Close acForm, "FrmCalendar2"
         End If
        
     Case "date_on_call_3"
            Form_frmStaffDetails.date_on_call_3 = CalObject.Value
            If ((CalObject.Value = Form_frmStaffDetails.date_on_call_1) Or (CalObject.Value = Form_frmStaffDetails.date_on_call_2)) Then
                MsgBox ("Invalid Date! Doctor cannot be on call at same times.")
            Else
            If (CalObject.Value < date) Then
                 MsgBox ("Invalid Date! The doctor cannot be on call on a previous date.")
         Else
            DoCmd.Close acForm, "FrmCalendar2"
         End If
    
     Case Else
            DoCmd.Close acForm, "frmCalendar2"
        
     End Select

End Sub

But when i run this code it comes up with an error saying Select case Without Case.... What does that mean and what do i have to?
Can anyone tell me?

Thanx

Junaid
 
Old February 5th, 2005, 08:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Junaid,

You are using nested If...Then statements with out using End If at the end of the outer If...Then block. Should be:

Select Case Value
    Case 1
        If contdition1 Then
            'dosomething...
        Else
            If condition2 Then
                'dosomething...
            End If
        'terminate the outer If...Then block
        End If
    Case Else
        'dosomethingelse...
End Select

If you leave out the End If for the outer condition then the Case statement isn't included in the Select Case block (hence the error), it's part of the unterminated If...Then block, which ain't legal.

HTH,

Bob







Similar Threads
Thread Thread Starter Forum Replies Last Post
select case bacster Classic ASP Basics 2 May 1st, 2006 06:31 PM
select case yuvalk SQL Server 2000 4 August 25th, 2004 02:33 PM
Select Case morpheus VB How-To 1 August 13th, 2003 09:14 AM
Select Case andy24 Classic ASP Databases 5 July 25th, 2003 07:52 AM
Select Case ziwez0 .NET Web Services 8 July 11th, 2003 02:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.