Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a tabbed form and on one of the tabs is a button I would like to enable for only some users, and disable for others.
    Each user is designated as either "A" (admin user) or "U" (regular user). This is done on a separate table.

    On the tabbed form I added a hidden field (called CurrentUserAdmin) that displays the user's designation (A or U). I wrote the following code to disable the button (called usercontrol), but it doesn't work - the button remains enabled despite the value of CurrentUserAdmin.

    If Me.CurrentUserAdmin.Value <> "A" Then
    Me.usercontrol.Enabled = False
    Else
    Me.usercontrol.Enabled = True
    End If

    I also tried:

    If Me.CurrentUserAdmin.Value <> "A" Then
    Me.usercontrol.Enabled = False
    ElseIf Me.CurrentUserAdmin.Value = "A" Then
    Me.usercontrol.Enabled = True
    End If


    I tried running the code on the OnCurrent event of the form.

    If I can't get the Enabled thing working, I would settle for using the Visible command to hide the button altogether.

    What am I doing wrong?

    Thanks,

    JoeK

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    UserControl is a built-in VBA property:
    "You can use the UserControl property to determine whether the current Microsoft Access application was started by the user or by another application with Automation, formerly called OLE Automation. Read/write Boolean."
    Perhaps this causes confusion.

    So I would rename the button, for example to cmdUserControl, and adjust the code accordingly:

    Code:
    Private Sub Form_Current()
      Me.cmdUserControl.Enabled = (Me.CurrentUserAdmin = "A")
    End Sub
    Does that work?

  3. #3
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because CurrentUserAdmin is a List Box (an important point I neglected to mention in my initial post - sorry), I discovered that I had to add ItemData(0) to your code.

    Code:
    Private Sub Form_Current()
      Me.cmdUserControl.Enabled = (Me.CurrentUserAdmin.ItemData(0) = "A")
    End Sub
    It now works perfectly.

    Thanks for your help,

    JoeK

Posting Permissions

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