Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Well, you can't just pull a field from a table out of nowhere in the sub. User is a table containing AccessID. You can pass it to the sub as a parameter:
    Private sub Command23_Click(strText as string, nUser as integer)
    You pass the AccessID to the sub as nUser, then


    Code:
    Select Case nUser
        case is = 1,7,10,11
               'use michigan
        case is = 1,8,10,12
                'use Oregon
        case is = 1,9,10,13
                'use California
        case else
    end select
    .
    But there's logic errors in this code and yours. If the nUser (AccessID) is 1 or 10, my code will always select Michigan, yours will always select California.
    Both can't be right but both can be WRONG!
    Whatcha think?

  2. #17
    Boost is offline Advanced Beginner
    Windows 8 Access 2013 64bit
    Join Date
    May 2018
    Posts
    47
    The following thread has been successfully solved by user davegri who crafted the below code which allows for a preassigned UserID to determine what fields are searchable in a form's search box.

    Thanks davegri !

    Option Compare Database

    Option Explicit


    Code:
    Private Sub cmdShowOregon_Click()
        Dim strSearch As String
        txtSearch = Null
        strSearch = "SELECT * from Personnel where [personnel-Unit] = 'Oregon'"
        Me.RecordSource = strSearch
        Me.Requery
        Me.txtCount = fcnCount
    End Sub
    
    
    Private Sub cmdShowTexas_Click()
        Dim strSearch As String
        txtSearch = Null
        strSearch = "SELECT * from Personnel where [personnel-Unit] = 'Texas'"
        Me.RecordSource = strSearch
        Me.Requery
        Me.txtCount = fcnCount
    End Sub
    
    
    Private Sub cmdShowWashington_Click()
        Dim strSearch As String
        txtSearch = Null
        strSearch = "SELECT * from Personnel where [personnel-Unit] = 'Washington'"
        Me.RecordSource = strSearch
        Me.Requery
        Me.txtCount = fcnCount
    End Sub
    
    
    Private Sub cmdShowAll_Click()
        Dim strSearch As String
        txtSearch = Null
        strSearch = "SELECT * from Personnel"
        Me.RecordSource = strSearch
        Me.Requery
        Me.txtCount = fcnCount
    End Sub
    
    
    Private Sub Command23_Click()
    Dim strText As String
    Dim strSearch As String
    strText = Trim(Me.txtSearch)
    
    
    If User.AccessID = 1 Or User.AccessID = 10 Then
        strSearch = "Select * from Personnel where " _
        & " [personnel-Unit] like ""*" & strText & "*"" or " _
        & " ([personnel_Surname] like ""*" & strText & "*"" or " _
        & " [personnel_Inits] like ""*" & strText & "*"" or " _
        & " [personnel_Rank/Title] like ""*" & strText & "*"" or " _
        & " [personnel_L6] like ""*" & strText & "*"" or " _
        & " [personnel_L7] like ""*" & strText & "*"" or " _
        & " [personnel_L4] like ""*" & strText & "*"" or " _
        & " [personnel_SVC#] like ""*" & strText & "*"") "
        Me.RecordSource = strSearch
        Me.Requery
        Me.txtCount = fcnCount
        Exit Sub
    End If
    
    
    If User.AccessID = 7 Or User.AccessID = 11 Then
        strSearch = "Select * from Personnel where ([personnel-Unit] = 'Washington') and " _
        & " ([personnel_Surname] like ""*" & strText & "*"" or " _
        & " [personnel_Inits] like ""*" & strText & "*"" or " _
        & " [personnel_Rank/Title] like ""*" & strText & "*"" or " _
        & " [personnel_L6] like ""*" & strText & "*"" or " _
        & " [personnel_L7] like ""*" & strText & "*"" or " _
        & " [personnel_L4] like ""*" & strText & "*"" or " _
        & " [personnel_SVC#] like ""*" & strText & "*"") "
        Me.RecordSource = strSearch
        Me.Requery
        Me.txtCount = fcnCount
        Exit Sub
    End If
    
    
    If User.AccessID = 8 Or User.AccessID = 12 Then
        strSearch = "Select * from Personnel where ([personnel-Unit] = 'Texas') and " _
        & " ([personnel_Surname] like ""*" & strText & "*"" or " _
        & " [personnel_Inits] like ""*" & strText & "*"" or " _
        & " [personnel_Rank/Title] like ""*" & strText & "*"" or " _
        & " [personnel_L6] like ""*" & strText & "*"" or " _
        & " [personnel_L7] like ""*" & strText & "*"" or " _
        & " [personnel_L4] like ""*" & strText & "*"" or " _
        & " [personnel_SVC#] like ""*" & strText & "*"") "
        Me.RecordSource = strSearch
        Me.Requery
        Me.txtCount = fcnCount
        Exit Sub
    End If
    
    
    If User.AccessID = 9 Or User.AccessID = 13 Then
        strSearch = "Select * from Personnel where ([personnel-Unit] = 'Oregon') and " _
        & " ([personnel_Surname] like ""*" & strText & "*"" or " _
        & " [personnel_Inits] like ""*" & strText & "*"" or " _
        & " [personnel_Rank/Title] like ""*" & strText & "*"" or " _
        & " [personnel_L6] like ""*" & strText & "*"" or " _
        & " [personnel_L7] like ""*" & strText & "*"" or " _
        & " [personnel_L4] like ""*" & strText & "*"" or " _
        & " [personnel_SVC#] like ""*" & strText & "*"") "
        Me.RecordSource = strSearch
        Me.Requery
        Me.txtCount = fcnCount
    End If
    End Sub
    
    
    Private Sub Form_Current()
        Call fcnCount
    End Sub
    
    
    'Private Sub Select_Click()
    '
    '    If InStr("|" & SelectedList, "|" & ID & "|") Then
    '       SelectedList = Replace(SelectedList, ID & "|", "")
    '    Else
    '       SelectedList = SelectedList & ID & "|"
    '    End If
    '
    'End Sub
    
    
    Private Sub Form_Open(Cancel As Integer)
        If User.AccessID = 1 Or User.AccessID = 10 Then
            Me.cmdShowAll.Enabled = True
            Me.cmdShowOregon.Enabled = True
            Me.cmdShowTexas.Enabled = True
            Me.cmdShowWashington.Enabled = True
            Exit Sub
        End If
    
    
        If User.AccessID = 7 Or User.AccessID = 11 Then
            Me.cmdShowWashington.Enabled = True
            Me.cmdShowOregon.Enabled = False
            Me.cmdShowTexas.Enabled = False
            Me.cmdShowAll.Enabled = False
            Exit Sub
        End If
    
    
        If User.AccessID = 8 Or User.AccessID = 12 Then
            Me.cmdShowTexas.Enabled = True
            Me.cmdShowOregon.Enabled = False
            Me.cmdShowWashington.Enabled = False
            Me.cmdShowAll.Enabled = False
            Exit Sub
        End If
    
    
        If User.AccessID = 9 Or User.AccessID = 13 Then
            Me.cmdShowOregon.Enabled = True
            Me.cmdShowTexas.Enabled = False
            Me.cmdShowWashington.Enabled = False
            Me.cmdShowAll.Enabled = False
        End If
    End Sub
    
    
    Private Function fcnCount() As Long
        If Me.RecordsetClone.RecordCount > 0 Then
            Me.Recordset.MoveLast
            Me.Recordset.MoveFirst
            fcnCount = Me.Recordset.RecordCount
        Else
            fcnCount = 0
        End If
    End Function
    Last edited by Boost; 08-22-2018 at 08:15 PM. Reason: Mapping the code block

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 07-02-2018, 03:26 PM
  2. need some assistance
    By WillemTWC in forum Access
    Replies: 20
    Last Post: 03-14-2018, 12:10 AM
  3. VBA assistance
    By Kwbrown in forum Programming
    Replies: 3
    Last Post: 03-15-2014, 03:09 PM
  4. Qry Assistance Please
    By buck in forum Access
    Replies: 8
    Last Post: 12-31-2013, 08:52 AM
  5. Some Assistance with sorting via VBA code
    By RachelBedi in forum Forms
    Replies: 7
    Last Post: 10-31-2012, 01:33 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