Results 1 to 6 of 6
  1. #1
    jisad09 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Location
    Sarasota, FL
    Posts
    3

    Perplexing If-Then-Else Statement...

    So this may seem trivial to some, but this is getting the best of me.



    Setup:
    I am building a database for a client and I have the need for a lengthy validation process. There is a form "frm_StationSettings" that is linked to a table "tbl_StationSettings". The VBA is fired off a _Click event on a form used to log into the different 'stations' located in their different offices. When clicked, the form checks the table to see if the station is in 'lockout' mode. If the *_Lockout.value on the table is true, then, instead of showing the regular form for their office, it shows a 'lockout' form. I am not sure why he wants it in there, or what he is going to accomplish with it in there, but he wants it.

    Here is the code I can not get to work. This is only two of 7 stations I have to insert into the _Click event. I keep getting block/end if errors. When nesting IF statements like this, I am just confused.

    Code:
    Private Sub cmdLogin_Click()
    If cboPortal.Value = "Administrator" And txtPassword.Value = "OSMGowns" Then
        If [Tables]![tbl_StationSettings]![Administrator_Lockout].Value = True Then
            cboPortal.Value = Null
            txtPassword.Value = Null
            DoCmd.Close
            DoCmd.OpenForm "lockout"
    
        Else:  cboPortal.Value = Null
                txtPassword.Value = Null
                DoCmd.Close
                DoCmd.OpenForm "LoggedIn_Administrator", acNormal, , , , acWindowNormal
    
    
    If cboPortal.Value = "Office Staff" And txtPassword.Value = "OSMGowns" Then
        If [Tables]![tbl_StationSettings]![OfficeStaff_Lockout].Value = True Then
            cboPortal.Value = Null
            txtPassword.Value = Null
            DoCmd.Close
            DoCmd.OpenForm "lockout"
    
        Else:  cboPortal.Value = Null
                txtPassword.Value = Null
                DoCmd.Close
                DoCmd.OpenForm "LoggedIn_OfficeStaff", acNormal, , , , acWindowNormal
    
    
    Else: MsgBox "Invalid Athentication Provided." & vbCrLf & "Please try again!", vbInformation, "Please Try Again!"
    
    
    End If
    End Sub
    Thank you in advance for any help. Let me know if you need anymore information!
    -Joel

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Well for starters, you can't get a table value that way. You can open a recordset or use DLookup().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jisad09 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Location
    Sarasota, FL
    Posts
    3
    Do you mind helping me with that? I have never dealt with a 'recordset' before. And I am shaky with DLookups.

  4. #4
    jisad09 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Location
    Sarasota, FL
    Posts
    3
    If it helps understanding...see attached.

    I striped all tables, queries, forms, and reports not related to my question.
    Attached Files Attached Files

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Many of the readers do not have Acc2007 or 2010 and can not open/use an accdb database.

    There are many examples on the internet showing how to use a recordset.
    Here is one that may help.
    http://ms-access-tips.blogspot.ca/20...e-lending.html


    ?? Where did you get the code you posted??

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    More on DLookup

    http://access.mvps.org/access/general/gen0018.htm

    If there's only one record, you don't need the criteria argument. Your error is because you start several If statements and only end one. Each If must have a corresponding End If. You may find Select/Case easier to work with.
    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. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  2. Perplexing scatter chart x-axis problem
    By whatwouldmattdo in forum Queries
    Replies: 3
    Last Post: 11-28-2011, 09:38 AM
  3. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  4. Perplexing Make Table error
    By jgelpi16 in forum Queries
    Replies: 4
    Last Post: 05-26-2011, 08:46 AM
  5. Perplexing Problem
    By karoly in forum Access
    Replies: 2
    Last Post: 01-02-2011, 07:08 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