Results 1 to 5 of 5
  1. #1
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97

    Help with Select Case statement

    In a "Select Case" statement I would like to tell :"Case is" last record in database.
    What is the right syntax ??

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    See http://www.techonthenet.com/access/f...anced/case.php

    and No you would'nt use that to get the last record.

    You could do something like

    rs.movelast
    .. do something here

  3. #3
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    maybe I was not clear.
    Here is my code :

    Select Case [ID]
    Case Is = "1"
    Me.Comando484.Visible = False
    Me.Comando485.Visible = True
    Case Max(ID) 'here is where I don't know exact syntax
    Me.Comando484.Visible = True
    Me.Comando485.Visible = False
    Case Else
    Me.Comando484.Visible = True
    Me.Comando485.Visible = True
    End Select

    Any hint ?

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    A couple of things -

    1. ID, if it is an autonumber, is not necessarily going to be the largest and the last record. Autonumbers, even if they are set to increment, can actually go random or negative numbers. So, unless you are using another method, you don't want that.

    2. If ID is numeric you don't use quotes around the 1 in the Case. You would just use

    Case 1

    3. This code should work:
    Code:
    Private Sub Form_Current()
    Dim rst As DAO.Recordset
    
    Set rst = Me.RecordsetClone
    
    rst.MoveLast
     
    Select Case Me!ID
       Case 1
          Me.Comando484.Visible = False
          Me.Comando485.Visible = True
       Case rst!ID 
          Me.Comando484.Visible = True
          Me.Comando485.Visible = False
       Case Else
          Me.Comando484.Visible = True
          Me.Comando485.Visible = True
       End Select
    
        rst.Close
        Set rst = Nothing
    End Sub

  5. #5
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    works like a charm
    thanks a ton!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. CASE STATEMENT or IF-ELSE-THEN? HELP
    By Shakenaw in forum Access
    Replies: 9
    Last Post: 06-08-2015, 11:24 AM
  2. case statement - multiple columns
    By eddiec in forum Queries
    Replies: 2
    Last Post: 07-05-2011, 03:24 AM
  3. Replies: 3
    Last Post: 05-06-2011, 02:49 PM
  4. Case or Switch in an update statement
    By allenjasonbrown@gmail.com in forum Queries
    Replies: 7
    Last Post: 11-17-2010, 01:49 AM
  5. Case Statement Syntax
    By allenjasonbrown@gmail.com in forum Programming
    Replies: 1
    Last Post: 11-16-2010, 07:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums