Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2006
    Location
    Mount Wolf, PA
    Posts
    21

    Question Unanswered: Having a fit with FindFirst

    Hello,

    What I would like to happen is compare User to the UserID field in tbl_Employees. If they match and IsUM or IsSA is true to open the form frm_1WorkEntry. If User and UserID match and only IsDE is true then open form frm_1WorkEntry_DE. Everyone else would receive a message that they do not have the permission to use the form. Any help would be appreciated. This is what I came up with, but of course, it does not work:


    Dim User As String, db As Database, RS2 As Recordset

    Set db = CurrentDb()
    Set RS2 = db.OpenRecordset("tbl_Employees", dbOpenDynaset)

    User = txtUserID.Value

    RS2.FindFirst ("[EmployeeID]" = User)
    If RS2.NoMatch = False And RS2("IsUM").Value = True Or RS2("IsSA").Value = True Then
    DoCmd.OpenForm "frm_1WorkEntry"
    ElseIf RS2.NoMatch = False And RS2("IsUM").Value = False And RS2("IsSA").Value = False And RS2("IsDE").Value = True Then
    DoCmd.OpenForm "frm_1WorkEntry_DE"
    Else
    MsgBox "You do not have permission to access this form", vbCritical, "Access Denied"
    End If

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Try returning only the relevant row of your dataset. Your criteria looks fine. Not sure why you're calling NoMatch though, is there a possibility of txtUserID not existing in tbl_Employees?

    Set RS2 = db.OpenRecordset ("SELECT * FROM tbl_Employees WHERE EmployeeID = " & txtUserId)
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Jan 2006
    Location
    Mount Wolf, PA
    Posts
    21

    Having a fit with FindFirst

    There is a possibility of txtUserID not existing in tbl_Employees. If there is an easier alternative, please let me know. Using Set RS2 = db.OpenRecordset("SELECT * FROM tbl_Employees WHERE EmployeeID = " & txtUserID), I receive a runtime error 3061 message: Too few parameters. Expected1.

    Thanks,
    em

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Oh, add your recordset type:

    Set RS2 = db.OpenRecordset ("SELECT * FROM tbl_Employees WHERE EmployeeID = " & txtUserId, dbOpenDynaset)

    Check recordcount for 0 before you do anything, as that is obviously not going to pass any of the other criteria.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •