Access2010 Navigation enable problems

beginner123

Registered User.
Local time
Today, 12:23
Joined
Apr 13, 2013
Messages
44
HI All,

I have created a Navigation form with a NavigationControl0.
Certain Navigation buttons are set to Enabled -No

I have another form ** Login ** where if the user logs in corretly I would like to enable a certain navigation button.

The is a cmdOK button on the Login form which On Click Event Procedure

Private Sub cmdOK_Click()

Dim rs As Recordset
Dim strSQL As String
Dim strPassword As String
Dim strUserName As String
Dim Userlogged As Boolean
On Error Resume Next
strUserName = Username.Value
strPassword = Password.Value
Set db = CurrentDb
strSQL = "SELECT password FROM sUser WHERE username='" & strUserName & "'"
Set rs = db.OpenRecordset(strSQL)
If rs.RecordCount > 0 Then
If rs.Fields(0) <> strPassword Then
MsgBox "Wrong username or password. Try again.", vbOKOnly, "Warning!"
Else
Me.Visible = False
'Userlogged = True
Username.Value = ""
Password.Value = ""
NavigationButton140.Enabled = True
MsgBox "Should be Enabled but isn't!", vbOKCancel
End If
Else
MsgBox "Wrong username or password. Try again.", vbOKCancel, "Warning!"
Username.Value = ""
Password.Value = ""
Username.SetFocus
End If
End Sub

Can someone please help or guide me in the right direction!
Many thanks
 

Attachments

  • image.gif
    image.gif
    41.7 KB · Views: 126
I'm not 100% clear what is or isn't happening but at a guess the problem is at this line and the button should get enabled?

NavigationButton140.Enabled = True
MsgBox "Should be Enabled but isn't!", vbOKCancel

if so try this:
me![NavigationButton140].Enabled = True
 
Hi and thanks for the reply.

Yes you are correct, I can't seem to enable the navigation button.

me![NavigationButton140].Enabled = True

Returns,
Run-time error 2465
Microsoft Access can't find field 'NavigationButton140' refered to in your expression.

Can you access NavigationButtons from other forms or code?

Many Thanks
 
Hi,

From the looks of things, the issue is that you are needing to enable a navigation button which is on the navigation form itself and not on your login form. The login form is displayed within a subform control on the navigation form so using Me syntax is telling Access to find the navigation button on the login form and it of course can't find it there.

The solution is to reference the navigation form's controls collection using syntax like so:
[Forms]![MainMenu]![NavigationButton140].Enabled = True

You'll need to substitute MainMenu there in the above example for the exact name of your navigation form.

--------------------
Jeff Conrad - Access Junkie - MVP Alumnus
SDET II - Access Test Team - Microsoft Corporation

Author - Microsoft Access 2013 Inside Out (coming soon)
Author - Microsoft Access 2010 Inside Out
Co-author - Microsoft Office Access 2007 Inside Out
Access 2007/2010 Info: http://www.AccessJunkie.com

----------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.mspx
----------
 
Hi, AccessJunkie

Thank you very much for the explanation. You are spot on.
Worked a dream, 1st stages of my learning curve.

Regards
Robin
 
Robin

If you are going to use this in a lot of situations you might wish to save the result in a Table or as a Public Variable.
 

Users who are viewing this thread

Back
Top Bottom