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"
![]()
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"
![]()
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.
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.
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.
this button is used as a display of whoever is logged in.
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.
i meant a textbox displaying the current user logged.
and button is navigation button on a subform with admin access only
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
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.
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.
I am using the Navigation Form Object.
I put it under form's load event and i get the below fault.
'the expression has an invalid reference to the parent property'
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.Me.btnewuser.Visible = Me.txtuser <> "admin"
txtuser is a textbox in the login form not in navigation 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.
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.
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