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: 310
Thanks: 157
Thanked 5 Times in 3 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: 310
Thanks: 157
Thanked 5 Times in 3 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: 487
Thanks: 6
Thanked 115 Times in 113 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: 487
Thanks: 6
Thanked 115 Times in 113 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: 310
Thanks: 157
Thanked 5 Times in 3 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,491
Thanks: 14
Thanked 272 Times in 270 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)
Old 08-24-2018, 11:20 AM   #37
psyc0tic1
Access Moron
 
Join Date: Jul 2017
Posts: 310
Thanks: 157
Thanked 5 Times in 3 Posts
psyc0tic1 is on a distinguished road
Re: A Little Help With Tab Control

So I finally got done with the conversion to tabbed controls... now the db takes forever to load.

With navigation control I believe it defers the forms loading until the corresponding navigation tab is clicked.

With the tabbed control the db loads all of the forms before it opens. Tripled the opening time of the database.

Sigh.

That was a lot of work for no gain.

__________________
Richard
Access 2013, Windows 7 64 bit
psyc0tic1 is offline   Reply With Quote
Old 08-24-2018, 12:23 PM   #38
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,491
Thanks: 14
Thanked 272 Times in 270 Posts
Mark_ will become famous soon enough
Re: A Little Help With Tab Control

IIRC, if you have disabled the sub-forms and other controls that would normally request data, they should not be loading until you enable the tab and control.
Mark_ is offline   Reply With Quote
Old 08-24-2018, 12:35 PM   #39
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 31,948
Thanks: 10
Thanked 3,849 Times in 3,792 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: A Little Help With Tab Control

I'm not sure disabling a subform prevents it from loading data. It would be nice if it did. If it doesn't, another solution is to either have a single subform control and switch which subform is displayed in it as you click on buttons/tabs, or load each subform as its tab is clicked on.
__________________
Paul
Microsoft Access MVP

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
Old 08-24-2018, 12:47 PM   #40
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,491
Thanks: 14
Thanked 272 Times in 270 Posts
Mark_ will become famous soon enough
Re: A Little Help With Tab Control

Paul,
I'm thinking default all controls on all tabs (including controls on subforms) to disabled. Then when you switch to a tab that is valid, you enable onload.
Mark_ is offline   Reply With Quote
Old 08-24-2018, 12:50 PM   #41
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 31,948
Thanks: 10
Thanked 3,849 Times in 3,792 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: A Little Help With Tab Control

I understand, I just don't know if disabling it will prevent it from loading data when the form loads. I'm not saying you're wrong, I honestly don't know. My gut says it will still load data, because a disabled control still shows its underlying data, you just can't click in it. I'll try to test if I get a minute.
__________________
Paul
Microsoft Access MVP

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
Old 08-24-2018, 01:03 PM   #42
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 31,948
Thanks: 10
Thanked 3,849 Times in 3,792 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: A Little Help With Tab Control

I was curious so did an exceedingly brief test. I had a bound form with a bound subform, with the subform control disabled. When opened, the subform still displayed the records it normally would have, I just couldn't click into the subform.

I guess another idea for quicker loading of multiple subforms is to set their record sources to return zero records by default, or no record source at all. When their tab is clicked on, set the record source back to what it would normally be.
__________________
Paul
Microsoft Access MVP

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
Old 08-24-2018, 01:19 PM   #43
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,491
Thanks: 14
Thanked 272 Times in 270 Posts
Mark_ will become famous soon enough
Re: A Little Help With Tab Control

Paul,

Did the same test, but came up with a slightly different way of doing this..
I created a table, TblBlank, with one field and one record.
I created a query that MATCHED the normal query used by a subform but with all of the fields change to expressions; [LastName] became LastName: "Last Name", [FirstName] became FirstName: "First Name", ect...
In the OnLoad for the subform I set the form's recordsource = "MyBlankTableQuery"
On the TAB, I set the OnClick for the subform to set Me.Subform.Form.Recordsource = "MyRealQuery".

Means that when I first moved to the tab, I got "Last Name" and "First Name" for a single row. When I CLICKED on the subform, it loaded the proper data.

psyc0tic1,
If you add a table that has one column and one row to your app (TblBlank is what I called mine) you can do the same trick. Means you'll have to make a copy of each of the initial queries and change them to look at tlbBlank and have them return the same fields in the same order, but it should avoid any issue with pulling data across the network.
Mark_ is offline   Reply With Quote
The Following User Says Thank You to Mark_ For This Useful Post:
psyc0tic1 (09-07-2018)
Old 08-24-2018, 01:31 PM   #44
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 31,948
Thanks: 10
Thanked 3,849 Times in 3,792 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: A Little Help With Tab Control

That's similar to where I was heading in post 42. I have this vague memory of the recordsource being evaluated in the open/load events, so if performance is still a problem, you may want to set the record source to the blank query in design view rather than the load event.
__________________
Paul
Microsoft Access MVP

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
Old 08-24-2018, 01:50 PM   #45
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,286 Times in 1,225 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
What I do with a tab control with subforms on each tab, is only load the subform for the currently visible tab by programmatically setting the SourceObject property of a single subform control.

Doing it that way is fast and simple. Handle the Change event of the tab control, detect the current page, load the subform that belongs on that page.

Mark

__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
The Following User Says Thank You to MarkK For This Useful Post:
psyc0tic1 (09-07-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
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:59 PM.


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