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

    Select Case using query field

    Do "Select Case" statements work with query fields ??
    In a form I am trying to implement the following code to prompt users to change password :



    Code:
    Select Case LastPwChange![Y]
    Case Is <= 90
    DoCmd.OpenForm [Recipient]
    Case Else
    MsgBox "Password expired. You must change it"
    DoCmd.OpenForm [frm_Change_Password]
    End Select
    but I receive runtime error 424 (object expected) and the debugger highlight the first line....
    FYI,

    LastPwChange is my query name
    [Y] is an expression field within the query ( Y: Min(Now()-[Date] )

    Please help!

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Sure, but you can't get the value from a query (or table) that way. Presuming that query is not the record source of the form, you need to either open a recordset or use DLookup() to get the value from it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    Quote Originally Posted by pbaldy View Post
    Sure, but you can't get the value from a query (or table) that way. Presuming that query is not the record source of the form, you need to either open a recordset or use DLookup() to get the value from it.
    Ok. I am trying to solve this. I have put a hidden control on the form (frmHelpAbout) which is bound to the value to [Y] and everything works with the If statement below
    Code:
    If Me![Y] <= 90 Then
    DoCmd.OpenForm "Recipient"
    ElseIf Me![Y] > 90 Then
    MsgBox "blah blah...."
    DoCmd.OpenForm "frm_Change_Password"
    End If
    The point is that when the query provides no records, I receive runtime error '2427' You have entered an expression that has no value. So I'm trying to add an if statement for when there are no records....

    Code:
    If Me![Y] <= 90 Then
    DoCmd.OpenForm "Recipient"
    ElseIf Me.RecordsetClone.RecordCount = 0 Then
    MsgBox "blah...."
    DoCmd.OpenForm "frm_Change_Password"
    ElseIf Me![Y] > 90 Then
    MsgBox "blah blah...."
    DoCmd.OpenForm "frm_Change_Password"
    End If
    but error 2427 persists.. What's wrong with my syntax ???

  4. #4
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    Fixed myself! I had to change to order of the If statements and made the Me.recordset.recordcount the first one !

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Glad you got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Select Query > Update Query > Table Field
    By tuggleport in forum Queries
    Replies: 2
    Last Post: 08-09-2012, 07:04 AM
  2. Help with Select Case statement
    By focosi in forum Access
    Replies: 4
    Last Post: 08-09-2011, 12:01 AM
  3. VBA "Select Case" Troubles
    By Dalagrath in forum Programming
    Replies: 14
    Last Post: 08-04-2011, 11:38 PM
  4. Replies: 3
    Last Post: 05-06-2011, 02:49 PM
  5. Is there a way to force a field do be upper case?
    By newtoAccess in forum Access
    Replies: 1
    Last Post: 11-28-2010, 04:20 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