Results 1 to 14 of 14
  1. #1
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55

    Syntax check: novice is missing something and can't figure it out...

    I know there's probably something simple I'm overlooking here, but I can't seem to figure it out. The code below is for a Log In form that works, with the exception of where it is supposed to open either the Main Menu or Editor based on the user status (Super_User - if True, open the Main Menu form, if False open the Editor form). Instead, it simply opens the Editor form regardless of the user status (Super_User). See where it says, "Close the Log In form and open either the Editor or Main Menu."



    The values come from a combo box (cboIdentity) where the user selects their name and where column 1 is the employee ID (Emp_ID), column 2 is the password (Emp_Pass), column 3 indicates whether the user is active or not (Active) and column 4 indicates the user's status (Super_User).

    Code:
    Option Compare Database
    Private intLogonAttempts As Integer
    Private Sub Form_Open(Cancel As Integer)
    'On open set focus to combo box
    Me.cboIdentity.SetFocus
    End Sub
    Private Sub cboIdentity_AfterUpdate()
    'After selecting user name set focus to password field
    Me.txtPassword.SetFocus
    End Sub
    Private Sub cmdLogin_Click()
    'Check to see if data has been selected from the Employee Name combo box
        If IsNull(Me.cboIdentity) Or Me.cboIdentity = "" Then
          MsgBox "You must select an Employee Name.", vbOKOnly, "Required Data"
            Me.cboIdentity.SetFocus
            Exit Sub
        End If
        'Check to see if data has been entered into the Password text box
        If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
          MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
            Me.txtPassword.SetFocus
            Exit Sub
        End If
        'Check the value of the password in tblEmployeeRoster to see if this
        'matches the value chosen in combo box
        If Me.txtPassword.Value = Me.cboIdentity.Column(2) Then
            Emp_ID = Me.cboIdentity.Value
            
            'Check to verify if the employee is still active in the database
            
            If Me.cboIdentity.Column(3) = False Then
                  MsgBox "You are no longer active in this database. Please contact Jennifer Wrobleski.", _
                   vbCritical, "Restricted Access!"
                Application.Quit
            Else
                'Close the Log In form and open either the Editor or Main Menu
            
                If Me.cboIdentity.Column(4) = True Then
                    DoCmd.OpenForm "frmMainMenu"
                Else
                    DoCmd.OpenForm "frmEmployeeData"
                End If
                DoCmd.Close acForm, "frmLogIn", acSaveNo
            End If
        Else
          MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
                "Invalid Entry!"
            Me.txtPassword.SetFocus
        End If
        'If User Enters incorrect password 3 times database will shutdown
        intLogonAttempts = intLogonAttempts + 1
        If intLogonAttempts > 3 Then
          MsgBox "Apparently you do not have access to this database. Please contact Jennifer Wrobleski.", _
                   vbCritical, "Restricted Access!"
            Application.Quit
        End If
    End Sub
    I also need to save the the user ID (Emp_ID) in "memory" for reference by a different form (when the editor form comes up it will need to open with the record for that particular user ID only, unless it's a super user (Super_User), in which case that user would have access to all records in the database. Any help would be greatly appreciated...

  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,530
    Column 4 is the 5th column in the combo's row source; is that appropriate? Does that column return True or False, or should the test be for a text value like "Super User"? To hold the value for later use, one solution is to hide the login form instead of closing it. You can still refer to it from other forms. You might set a breakpoint to examine the value in the combo at runtime:

    http://www.baldyweb.com/Debugging.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    Thanks, Paul -

    I set a break point at:

    If Me.cboIdentity.Column(4) = True Then

    and "stepped into" (using F8) and what I discovered is it's "skipping over" the next line:

    DoCmd.OpenForm "frmMainMenu"

    and going straight to:

    Else

    at this segment of the code:

    Code:
                'Close the Log In form and open either the Editor or Main Menu
            
                If Me.cboIdentity.Column(4) = True Then
                
                    DoCmd.OpenForm "frmMainMenu"
                Else
                    DoCmd.OpenForm "frmEmployeeData"
                End If
                DoCmd.Close acForm, "frmLogIn", acSaveNo
            End If
    Why would it "skip" the line "DoCmd.OpenForm "frmMainMenu" (and not open the Main Menu)? I "hovered" over that line where I put the break (If Me.cboIdentity.Column(4) = True Then) and the value appears to be null (it shows "Me.cboIdentity.Column(4) = Null"). It shows the same value if I put a "5" in there ("Me.cboIdentity.Column(5) = Null").

    Thoughts?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    It skips the line because the condition wasn't met (value not True). Can you post the db here? Or what the combo row source is, and the column count property?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    Sure - here's the row source SQL for that combo (cboIdentity):

    SELECT tblEmployeeRoster.Emp_ID, Emp_ID & " - " & [Last_Name] & ", " & [First_Name] AS Expr1, tblEmployeeRoster.Emp_Pass, tblEmployeeRoster.Active, tblEmployeeRoster.Super_User
    FROM tblEmployeeRoster
    ORDER BY tblEmployeeRoster.Last_Name, tblEmployeeRoster.First_Name;

    From the datasheet view it shows the following columns: Emp_ID, (that expression - Expr1: Emp_ID & " - " & [Last_Name] & ", " & [First_Name]), Emp_Pass, Active, Super_User

    The "Column Count" says 3... The Column Widths says 0";1";0";0";0" I think I may know my answer now - the "Column Count" need to be set to 4? 5?

  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,530
    The column count needs to be the number of columns, in this case 5. The lower setting is preventing the code from "seeing" that column.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    That worked - except the column is 4 (If Me.cboIdentity.Column(4) = True Then). I knew it had to be something simple. Thanks!!! Kinda feel silly...

    Back to your other suggestion of hiding the form. I assume the syntax at DoCmd.Close acForm, "frmLogIn" simply needs to be modified to hide it instead of closing it - ? Would hiding the Log In form cause any issues? If I want to "use" the information from it, I would simply reference it (Me.cboIdentity.Value), yes? So, for example, when the Editor form pulls up, right now the Row Source for the particular form is based on this query:

    SELECT tblEmployeeRoster.Emp_ID AS tblEmployeeRoster_Emp_ID, tblEmployeeRoster.First_Name, tblEmployeeRoster.Last_Name, tblEmployeeRoster.Position_Title, tblEmployeeRoster.Functional_Area, tblEmployeeRoster.Active, tblEmployeeKSA.Emp_ID AS tblEmployeeKSA_Emp_ID, tblEmployeeKSA.Bilingual, tblEmployeeKSA.Exp_Mgmt, tblEmployeeKSA.Exp_HCare, tblEmployeeKSA.Degree_Assoc, tblEmployeeKSA.Degree_Bchlr, tblEmployeeKSA.Degree_Mstr, tblEmployeeKSA.Degree_Dr, tblEmployeeKSA.Degree_Nsing, tblEmployeeKSA.Degree_Otr, tblEmployeeKSA.Cert_CPA_Cert, tblEmployeeKSA.Cert_CPA, tblEmployeeKSA.Cert_CFE, tblEmployeeKSA.Cert_AHFI, tblEmployeeKSA.Cert_CIA, tblEmployeeKSA.Cert_Coder, tblEmployeeKSA.Cert_PMP, tblEmployeeKSA.Cert_Otr, tblEmployeeKSA.HCExp_A, tblEmployeeKSA.HCExp_AofB, tblEmployeeKSA.HCExp_B, tblEmployeeKSA.HCExp_C, tblEmployeeKSA.HCExp_D, tblEmployeeKSA.HCExp_HH, tblEmployeeKSA.HCExp_DME, tblEmployeeKSA.HCExp_Psych, tblEmployeeKSA.HCExp_VA, tblEmployeeKSA.HCExp_Pvt, tblEmployeeKSA.HCExp_Caid, tblEmployeeKSA.HCExp_Rx, tblEmployeeKSA.HCExp_RRx, tblEmployeeKSA.HCExp_IRx, tblEmployeeKSA.HCExp_PRx, tblEmployeeKSA.HCExp_HInf, tblEmployeeKSA.HCExp_LTC, tblEmployeeKSA.HCExp_RxMkt, tblEmployeeKSA.HCExp_RxProd, tblEmployeeKSA.HCExp_RxAudit, tblEmployeeKSA.OtrExp_MedRcdAud, tblEmployeeKSA.OtrExp_ClmAud, tblEmployeeKSA.OtrExp_CostRptAud, tblEmployeeKSA.OtrExp_ComplAud, tblEmployeeKSA.OtrExp_DeskAud, tblEmployeeKSA.OtrExp_FinAud, tblEmployeeKSA.OtrExp_RecvAud, tblEmployeeKSA.OtrExp_CostRptInv, tblEmployeeKSA.OtrExp_HCareInv, tblEmployeeKSA.OtrExp_OtrInv, tblEmployeeKSA.OtrExp_CourtTmny, tblEmployeeKSA.OtrExp_TngPres, tblEmployeeKSA.OtrExp_DataAnal, tblEmployeeKSA.OtrExp_Nursing, tblEmployeeKSA.OtrExp_ClmAppeal, tblEmployeeKSA.OtrExp_CostRptApl, tblEmployeeKSA.OtrExp_MedCod, tblEmployeeKSA.OtrExp_ProjMgmt, tblEmployeeKSA.OtrExp_PropDev, tblEmployeeKSA.OtrExp_QualMgmt, tblEmployeeKSA.OtrExp_EnrElig, tblEmployeeKSA.OtrExp_COB, tblEmployeeKSA.OtrExp_VA, tblEmployeeKSA.OtrExp_Military, tblEmployeeKSA.OtrExp_TPL, tblEmployeeKSA.OtrExp_HIns, tblEmployeeKSA.OtrExp_CRecr, tblEmployeeKSA.OtrExp_EDI, tblEmployeeKSA.Contr_ZPIC, tblEmployeeKSA.Contr_PSC, tblEmployeeKSA.Contr_AMIC, tblEmployeeKSA.Contr_MEDIC, tblEmployeeKSA.Contr_PDDC, tblEmployeeKSA.Contr_RAC, tblEmployeeKSA.Contr_EEV, tblEmployeeKSA.Contr_CareMC, tblEmployeeKSA.Contr_IPERA, tblEmployeeKSA.Contr_MEDIC_OE, tblEmployeeKSA.Contr_VA, tblEmployeeKSA.Contr_Other, tblEmployeeKSA.Date_Modified, tblEmployeeKSA.Time_Modified
    FROM tblEmployeeRoster INNER JOIN tblEmployeeKSA ON tblEmployeeRoster.[Emp_ID] = tblEmployeeKSA.[Emp_ID]
    WHERE (((tblEmployeeRoster.Active)=True));

    (There is a lot of field information in the form - 2 tables are linked, the "roster" table and the "KSA" table). I would need to reference Me.cboIdentity.Value in Emp_ID field?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Instead of the close line:

    Me.Visible = False

    To reference it, note you can only use "Me" if the code is in that form (Me refers to the object containing the code, and is only valid in VBA code). From other forms, you'd need the full form reference:

    Forms Refer to Form and Subform properties and controls
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Another way to pass the "Emp_ID" value to a different form is to use the "OpenArgs" argument of the "OpenForm" command.

    See the example at BaldyWeb: http://www.baldyweb.com/OpenArgs.htm
    You could hide the form or close it....

  10. #10
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    Thanks again, Paul!

    Pardon my ignorance, but what's the best approach on the Editor form? The order of operations I was thinking was after the user logs in (and it checks their password, if they're active and what user type they are) it would either open the Editor form or the Main Menu, depending on the user type (Super_User = true or false). If True, the Main Menu opens and the super user can choose to go to the same Editor or run some reports. If false, the Editor opens and it opens with the data for that particular user (based on their user ID - Emp_ID).

    On the Editor form itself, I was thinking it would evaluate which user it is (super or not, based on the value in Super_User) and IF Super_User = True, then no filter would be applied unless they wanted to run a search, in which case a button to a sub form would be visible that would feed filter criteria to the record source for the form.

    I have some older code for a different database somebody created for me which does something similar (see below). I thought I could create a modified version of it for the Record Source on the Editor form. Thoughts?

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub btnAll_Click()
    Dim strSQL As String
    With Me
        'The SQL statement WHERE clause to be applied to this subform will include ALL records, ie contract_id > 0...
        'strSQL = "SELECT Contract_ID, Contract_Number, Contract_Name, Entity, Agency, Service_Agreement " & _
            "FROM tbl_Contract " & _
            "WHERE Contract_ID > 0"
        strSQL = "SELECT Contract_ID, Contract_Number, Contract_Name, Entity, Agency, Service_Agreement, LOB_Program, " & _
            "IIf(End_Date>=Now(),""Current"",""Expired"") AS Contract_Status " & _
            "FROM tbl_Contract "
        .RecordSource = strSQL
        .Filter = "contract_id > 0"
        'Apply the filter
        .Requery
        
        'Erase the values of the search controls...
        .cmbAgencySearch = ""
        .cmbContractTypeSearch = ""
        .cmbEntitySearch = ""
        .cmbServiceAgreementSearch = ""
        .cmbLOBSearch = ""
        .lblNoRecordsFound.Visible = False
    End With
    Debug.Print strSQL
    End Sub
    Private Sub btnSelect_Click()
    'After clicking on a particular contract's Edit button, the Contract form's record source will change to the SQL statement below...
    'To the Contract form, apply a filter of contract_id = the value of the txtContractID control...
    With Me.Parent
        .RecordSource = "SELECT * " & _
            "FROM tbl_Contract WHERE " & _
            "Contract_ID = " & Me.txtContractID
        .Requery
    End With
    End Sub
    
    Private Sub btnSetFilter_Click()
    Dim blnDoSearch As Boolean
    Dim strSQL As String
    Dim strSQLOrderBy As String
    Dim strSQLWhere As String
    blnDoSearch = False
    'Build the SQL that will be used as the filter for this contract search form...
    'SELECT subclause....
    strSQL = "SELECT DISTINCT c.Contract_ID, c.Contract_Name, c.Contract_Number, c.Agency, c.Entity, c.LOB_Program,  " & _
        "IIf(c.End_Date>=Now(),""Current"",""Expired"") AS Contract_Status " & _
        "FROM tbl_Contract AS c "
    'ORDER BY subclause...
    strSQLOrderBy = "GROUP BY c.Contract_ID, c.Contract_Name, c.Contract_Number, c.Agency, c.Entity, c.LOB_Program, c.End_Date " & _
        "ORDER BY c.Contract_Name;"
    'Set the WHERE clause based on values set in the search controls...
    With Me
        If .cmbContractTypeSearch <> "" Then
            strSQLWhere = strSQLWhere & "AND c.contract_type = """ & Me.cmbContractTypeSearch & """ "
        End If
        
        If .cmbEntitySearch <> "" Then
            strSQLWhere = strSQLWhere & "AND c.entity = """ & Me.cmbEntitySearch & """ "
        End If
        
        If .cmbLOBSearch <> "" Then
            strSQLWhere = strSQLWhere & "AND c.lob_program = """ & .cmbLOBSearch & """ "
        End If
        
        If .cmbServiceAgreementSearch <> "" Then
            strSQLWhere = strSQLWhere & "AND c.service_agreement = """ & Me.cmbServiceAgreementSearch & """ "
        End If
        
        If .cmbAgencySearch <> "" Then
            strSQLWhere = strSQLWhere & "AND c.agency = """ & Me.cmbAgencySearch & """ "
        End If
        
    End With
    Finish_SQL:
    'If the WHERE clause has a value then apply it to the subform...
    If strSQLWhere <> "" Then
        strSQLWhere = "WHERE " & Right(strSQLWhere, Len(strSQLWhere) - 4)
        Debug.Print strSQL & strSQLWhere & strSQLOrderBy
    End If
    With Me
        .RecordSource = strSQL & strSQLWhere & strSQLOrderBy
        .Requery
    End With
    'If no records are found, then display the "No records found" label...
    If Me.RecordsetClone.RecordCount = 0 Then
        Me.lblNoRecordsFound.Visible = True
    Else
        Me.lblNoRecordsFound.Visible = False
    End If
    End Sub

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    "Best" is usually a subjective term. For your app, best is what works best for you and your users, not what I or anybody else thinks is the best way to do something. You can certainly change the recordsource of the form based on the user type, you can have buttons or other controls that are only visible for the super user, etc. You can use this technique to open the form filtered as well:

    BaldyWeb wherecondition

    You figure out what the best flow is for your app, and we'll try to make it happen!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    Thanks again, Paul and Steve -

    I'll hunker in my "man cave" a bit and tinker with it. My preference is always the simplest method - something that will be easy to troubleshoot and maintain. Getting too fancy would throw me off. You have given me some good suggestions; again, I'll toy around with it a bit and let you know if I get into a jam.

    Appreciate your continued support - you guys are awesome!

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You've got a man cave?!? I'm jealous.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    Well, I like to think of it that way, anyway - sometimes I'm frequented by "visitors."

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

Similar Threads

  1. Replies: 9
    Last Post: 01-22-2013, 04:23 PM
  2. Missing check box data in report
    By Reaper in forum Reports
    Replies: 2
    Last Post: 01-31-2012, 07:27 AM
  3. Syntax error missing operator(3075)
    By parisienne in forum Programming
    Replies: 1
    Last Post: 04-07-2011, 02:29 PM
  4. Syntax Error...missing operator
    By jgelpi16 in forum Programming
    Replies: 14
    Last Post: 09-09-2010, 11:35 AM
  5. Replies: 9
    Last Post: 04-27-2010, 01:00 PM

Tags for this Thread

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