Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    gdhaliwal is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2024
    Posts
    10

    Need Help in Hiding a button if textbox value is admin

    hello all,

    I have a login form, which is transferring the username to a another form's textbox.
    See code below for Login screen.



    I want to hide a Navigation button (btnewuser) when that text field is "admin".
    name of the textbox is "userlogged"


  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Set the button as not visible in design and then only make it visible if needed.

    There is no code in your post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    gdhaliwal is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2024
    Posts
    10
    this is my 'Login Enter' button code.

    ''MsgBox "Welcome to Database"
    DoCmd.OpenForm "Navigation Form", acNormal
    DoCmd.Maximize
    Forms![Navigation Form]!userlogged = Me.txtuser
    DoCmd.Close acForm, "Login", acSaveYes

    Navigation form opens with the userlogged textbox displaying the userlogged.
    if userlogged is "admin" then i want to hide navigation button named btnewuser.

    i tried a lot of code. did not work.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Code behind Navigation form.

    Me.btnewuser.Visible = Me.txtuser <> "admin"

    Why would a user need this button? DB should already know if they are valid user. The code should check Users table for username and if not found present a new user form or do whatever is needed to create new user record.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    gdhaliwal is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2024
    Posts
    10
    this button is used as a display of whoever is logged in.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    A button and not a textbox or label?
    Does this button do anything?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    gdhaliwal is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2024
    Posts
    10
    i meant a textbox displaying the current user logged.

    and button is navigation button on a subform with admin access only

  8. #8
    gdhaliwal is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2024
    Posts
    10
    Private Sub Form_Load()
    Me.btnewuser.Visible = Me.txtuser <> "admin"
    End Sub

    .txtuser DATA member not found

    txtuser is a textbox in the login form not in navigation form

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    References on a navigation form are like this
    Forms![main navigation form].[NavigationSubform].Form.txtUser

    Note that when you "switch" to another form using the nav controls, the form you were on is closed. If your textbox is on that loaded form, this approach will probably not be useful.

    EDIT- the bracketed are references, not necessarily the real name of the form or controls you are using.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Is this a normal form/subform arrangement? Or are you using the Navigation Form object?

    Textbox is on main form and button is on subform?

    Try:

    Me.btnewuser.Visible = Me.Parent.txtuser <> "admin"


    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    gdhaliwal is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2024
    Posts
    10
    I am using the Navigation Form Object.

  12. #12
    gdhaliwal is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2024
    Posts
    10
    I put it under form's load event and i get the below fault.
    'the expression has an invalid reference to the parent property'

  13. #13
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Me.btnewuser.Visible = Me.txtuser <> "admin"
    txtuser is a textbox in the login form not in navigation form
    From several posts, I interpret the button is on a subform that the nav form opens, but the tb that may contain "admin" is on the form that opens the nav form, not the subform and not the nav form.

    If that is not correct then I think you should copy the db (you can delete from the copy db anything not needed for this), zip it and post here, because we're not getting anywhere with understanding the design. If the db is split then both parts might be required.

    Or you need to walk us through the steps that happen.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    gdhaliwal is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2024
    Posts
    10
    Apologies for the confusion.

    I have a login screen, where username is entered, and that username is copied onto the main navigation form using below code.

    Private Sub Command13_Click()


    Dim rst As Dao.Recordset
    Dim strsql As String
    strsql = "Select *from tbl_login where username = '" & txtuser.Value & " ' and " & " strcomp(password, '" & txtPassword.Value & "', 0) = 0"
    Set rst = CurrentDb.OpenRecordset(strsql)
    If rst.EOF Then
    MsgBox "Username or Password is incorrect", vbCritical, "Invalid Login"
    Else
    ''MsgBox "Welcome to Database"
    DoCmd.OpenForm "Navigation Form", acNormal
    DoCmd.Maximize
    Forms![Navigation Form]!userlogged = Me.txtuser
    DoCmd.Close acForm, "Login", acSaveYes
    End If
    rst.Close
    Set rst = Nothing

    When the navigation form opens up, it displays the textbox (userlogged) in the main header of the navigation form.

    The button i am trying to hide is one of the navigation buttons when that textbox (userlogged) is entered as "admin" from the login screen.

    Hope that is more clear
    Thanks for support.

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,266
    You could pass in Me.txtUser as OpenArgs and then test for that in the form load.
    That is the way I would probably do it, as you are setting that value as you are now, but then you need to run the test.

    I would do that in a Form Load event, so use OpenArgs, which is what it is there for?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. hiding a button on a report line
    By StuartR in forum Reports
    Replies: 2
    Last Post: 02-23-2018, 01:30 PM
  2. Replies: 2
    Last Post: 04-29-2016, 09:06 PM
  3. Replies: 6
    Last Post: 02-26-2016, 05:28 AM
  4. Use cmd button to fill textbox
    By shariq1989 in forum Forms
    Replies: 1
    Last Post: 07-19-2012, 08:59 AM
  5. Button hiding when filter on
    By rstonehouse in forum Forms
    Replies: 2
    Last Post: 08-25-2010, 06:24 AM

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