Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-10-2018, 09:44 AM   #31
psyc0tic1
Access Moron
 
Join Date: Jul 2017
Posts: 185
Thanks: 90
Thanked 2 Times in 2 Posts
psyc0tic1 is on a distinguished road
Re: A Little Help With Tab Control

Well it almost worked.

As I started testing:
I logged in as user1 (admin) and all tabs showed.
I logged in as user2 (Visual Inspector) and the proper tabs showed.
I logged in as user3 (Lab Tester) and I got a run-time error "2165" "You can't hide a control that has the focus". highlighted this line: "tb.Pages(1).Visible = False" under "Case 3" in the frm_home code.
I logged in as user4 (Multi Inspector) and the proper tabs showed.
I logged in as user5 (engineer) and the proper tabs showed.

I am confused... when you open the form that is on page 1 the first field after the combobox is selected.

However... page 1 gets False if you log in as user5 and it doesn't throw that run-time error

user1 (admin) sees page 1
user2 (visual inspector) sees page 1
user3 (lab tester) does not see page 1 **ERROR**
user4 (multi tester) sees page 1
user5 (engineer) does not see page 1 **NO ERROR**

Also if hiding a page with a control that has focus is an issue... the form that is on page 2 has the first field after the combobox with focus but no errors are thrown up about hiding that one.

__________________
Richard
Access 2013, Windows 7 64 bit
psyc0tic1 is offline   Reply With Quote
Old 08-10-2018, 10:11 AM   #32
psyc0tic1
Access Moron
 
Join Date: Jul 2017
Posts: 185
Thanks: 90
Thanked 2 Times in 2 Posts
psyc0tic1 is on a distinguished road
Re: A Little Help With Tab Control

Well I got around the issue by adding:
Code:
Me.LabInputForm.SetFocus
Right after "Case 3" and before the calls to visible or not

Don't know if that was the right way but it worked
__________________
Richard
Access 2013, Windows 7 64 bit
psyc0tic1 is offline   Reply With Quote
Old 08-10-2018, 11:27 AM   #33
MajP
Newly Registered User
 
Join Date: May 2018
Posts: 290
Thanks: 3
Thanked 69 Times in 67 Posts
MajP will become famous soon enough
Re: A Little Help With Tab Control

There was no need to modify the code. As I said the only thing you had to do was pass in the access level and it worked. This is all you had to do and the code would have worked 100%
Code:
Private Sub Command1_Click()
    Dim AccLvl As Integer
    If IsNull(Me.txtLoginID) Then
        MsgBox "Please Enter Login", vbInformation, "Need ID"
        Me.txtLoginID.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
        MsgBox "Please Enter Password", vbInformation, "Need Password"
        Me.txtPassword.SetFocus
    Else
        Credentials.UserName = Me.txtLoginID.Value
        If DLookup("Password", "tbl_users", "UserName = '" & Credentials.UserName & "'") = Me.txtPassword Then
            Credentials.UserId = DLookup("ID", "tbl_users", "UserName = '" & Credentials.UserName & "'")
            'Credentials.AccessLvlID = DLookup("AccessLvl", "tbl_users", "UserName = '" & Credentials.UserName & "'")
           'Get the access level and pass it to the form in the using open args which is the 7th argument of the Docmd.openform
            AccLvl = DLookup("ID", "tbl_users", "UserName = '" & Credentials.UserName & "'")
            DoCmd.OpenForm "frm_home", , , , , , AccLvl

            DoCmd.Close acForm, Me.Name
         End If
    End If
End Sub

MajP is offline   Reply With Quote
The Following User Says Thank You to MajP For This Useful Post:
psyc0tic1 (08-10-2018)
Old 08-10-2018, 11:32 AM   #34
MajP
Newly Registered User
 
Join Date: May 2018
Posts: 290
Thanks: 3
Thanked 69 Times in 67 Posts
MajP will become famous soon enough
Re: A Little Help With Tab Control

When you are showing and hiding things it is often much simpler to first simply show everything with a loop and hide selected items, or hide everything and show selected items. That was why my code seems shorter. If it was admin I did hid nothing. Else i ran a loop first to hide everything except tab 5. Then I use the select case to show the appropriate items. And yes when you hide something you cannot let it have the focus. That is why in my code I put the focus on tab 5 first since it never gets hidden.
MajP is offline   Reply With Quote
The Following User Says Thank You to MajP For This Useful Post:
psyc0tic1 (08-10-2018)
Old 08-10-2018, 11:53 AM   #35
psyc0tic1
Access Moron
 
Join Date: Jul 2017
Posts: 185
Thanks: 90
Thanked 2 Times in 2 Posts
psyc0tic1 is on a distinguished road
Re: A Little Help With Tab Control

Fine!... Let's do it your way!

Just kidding... much simpler code. I was actually proud of myself for making it work even though I knew there was a simpler way.

The only thing about that... there are only 2 scenarios in which I want the UserCP (page 5) to be set focused and that is if the user has a password of "password" or they have not yet filled in their security questions and answers.

Otherwise the first page with the left most tab should have focus
__________________
Richard
Access 2013, Windows 7 64 bit
psyc0tic1 is offline   Reply With Quote
Old 08-13-2018, 10:07 AM   #36
Mark_
Longboard on the internet
 
Join Date: Sep 2017
Location: Not the middle of no where, but I can see the road to it from my house.
Posts: 1,383
Thanks: 14
Thanked 257 Times in 255 Posts
Mark_ will become famous soon enough
Re: A Little Help With Tab Control

Then have a piece of code that checks the security first and sets focus as needed (to a tab you know WON'T be hidden) followed by MajP's code.

Mark_ is offline   Reply With Quote
The Following User Says Thank You to Mark_ For This Useful Post:
psyc0tic1 (08-13-2018)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Control Anchoring - Control to Control? (2007) stevenblanc Forms 3 07-21-2011 04:09 AM
Stuck: Searching Controls for a specific control name and changing the control value YevS Modules & VBA 2 07-09-2009 01:10 AM
Make one control's selection determin how another control is populated Paul-ish Forms 1 08-15-2007 06:45 PM
[SOLVED] Error: The control or subform control is too large for this location jsprenk Forms 0 07-11-2006 10:01 AM
"Can't Reference a control's Property or Method Unless The Control Has the Focus Dugantrain Forms 4 01-16-2003 12:30 PM




All times are GMT -8. The time now is 06:39 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World