Go Back   Access World Forums > Microsoft Access Reference > Microsoft Access Tutorials

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 07-26-2016, 10:04 PM   #1
shatteras
Newly Registered User
 
Join Date: Apr 2016
Posts: 25
Thanks: 5
Thanked 3 Times in 3 Posts
shatteras is on a distinguished road
unload subforms within a tab of a mainform

I am using a code I found on the net to log use of forms. (who opens it and when), the problem I am facing is, the code works if I put it in the "onload" event of a form. BUT, the forms are subforms within different tabs of the main form, so when I load the main form, the subforms in the tabs are also loaded technically. I am beginning to confuse myself here LOL!
I need help..
I need to log who's opening the tabs/subforms within the tabs. to make it shorter, I want to have a log who is looking at that particular tabs/subform.

thank you very much in advance.

shatteras is offline   Reply With Quote
Old 07-26-2016, 11:38 PM   #2
arnelgp
Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 6,847
Thanks: 55
Thanked 2,183 Times in 2,094 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: unload subforms within a tab of a mainform

then put also your code the the subforms' load event.
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 07-26-2016, 11:42 PM   #3
shatteras
Newly Registered User
 
Join Date: Apr 2016
Posts: 25
Thanks: 5
Thanked 3 Times in 3 Posts
shatteras is on a distinguished road
Re: unload subforms within a tab of a mainform

thank you for your response sir. but unfortunately, as I have mentioned earlier, when I put it "onload" event of the form (which is a subform within a tab control embedded to a main form), it will log the opening of the main form even if I am not selecting that particular tab. I am currently trying to unload the subforms within that tabs so when I click on that tab, only then will it fire an on load event. then unloads when I click another. I am trying many things already... whew...

shatteras is offline   Reply With Quote
Old 07-26-2016, 11:57 PM   #4
arnelgp
Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 6,847
Thanks: 55
Thanked 2,183 Times in 2,094 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: unload subforms within a tab of a mainform

ok, then, make the sourceobject of the subform to nothing first.
on the click of the tab, reinstate its sourceobject.
when one click another tab, again set the sourceobject to nothing, etc....
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 07-27-2016, 12:02 AM   #5
shatteras
Newly Registered User
 
Join Date: Apr 2016
Posts: 25
Thanks: 5
Thanked 3 Times in 3 Posts
shatteras is on a distinguished road
Re: unload subforms within a tab of a mainform

thank you,. I will try and be right back... I hope this works...
shatteras is offline   Reply With Quote
Old 07-27-2016, 12:17 AM   #6
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 9,502
Thanks: 360
Thanked 779 Times in 744 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Handling Tabs is a bit counter intuitive. I think you may find this thread helpful:-

http://www.access-programmers.co.uk/...ad.php?t=83036

Sent from my SM-G925F using Tapatalk
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
Old 07-27-2016, 01:35 AM   #7
shatteras
Newly Registered User
 
Join Date: Apr 2016
Posts: 25
Thanks: 5
Thanked 3 Times in 3 Posts
shatteras is on a distinguished road
Re: unload subforms within a tab of a mainform

the "unloading" plan didn't work could you please help me in how exactly should I remove the source object while it is not yet clicked or the tab is not active? thanks a bunch

thank you too uncle gizmo, I'm also reading that thread.

shatteras is offline   Reply With Quote
Old 07-27-2016, 03:10 AM   #8
arnelgp
Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 6,847
Thanks: 55
Thanked 2,183 Times in 2,094 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: unload subforms within a tab of a mainform

here take a look at this sample. observe the Load event of the main form. check also the click event of the tab control.
Attached Files
File Type: accdb tabs.accdb (476.0 KB, 112 views)
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 07-27-2016, 03:11 AM   #9
shatteras
Newly Registered User
 
Join Date: Apr 2016
Posts: 25
Thanks: 5
Thanked 3 Times in 3 Posts
shatteras is on a distinguished road
Re: unload subforms within a tab of a mainform

can you please take a look at this code.... the first tab, is working. it won't load unless I click on it. but the rest remains blank even if I click on it angrily
also because of this, the log for users who is clicking on the first tab is also working. now all I have to do is make the other tabs work like the first tab. THANK YOU.


Private Sub tab_ops_Change()
If Me.tab_ops.Value = 0 Then
If Me!OPERATIONSops.SourceObject = "" Then
Me!OPERATIONSops.SourceObject = "OPERATIONSops"
If Me.tab_ops.Value = 1 Then
If Me!OPERATIONSgascom.SourceObject = "" Then
Me!OPERATIONSgascom.SourceObject = "OPERATIONSgascom"
If Me.tab_ops.Value = 2 Then
If Me!OPERATIONSdiesel.SourceObject = "" Then
Me!OPERATIONSdiesel.SourceObject = "OPERATIONSdiesel"
If Me.tab_ops.Value = 3 Then
If Me!OPERATIONScrude.SourceObject = "" Then
Me!OPERATIONScrude.SourceObject = "OPERATIONSutilities"
If Me.tab_ops.Value = 3 Then
If Me!OPERATIONSutilities.SourceObject = "" Then
Me!OPERATIONSutilities.SourceObject = "OPERATIONSutilities"
If Me.tab_ops.Value = 4 Then
If Me!OPERATIONSoil.SourceObject = "" Then
Me!OPERATIONSoil.SourceObject = "OPERATIONSoil"

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End Sub
shatteras is offline   Reply With Quote
Old 07-27-2016, 03:54 AM   #10
shatteras
Newly Registered User
 
Join Date: Apr 2016
Posts: 25
Thanks: 5
Thanked 3 Times in 3 Posts
shatteras is on a distinguished road
Re: unload subforms within a tab of a mainform

SIR THANK YOU FOR THE REFERENCE!!!! it's now working like a charm, plus my code for log can be triggered with the on load of the forms. thank you again for the help sir!!!! here's how I wrote the code based on your sample

Private Sub tab_ops_Click()
If Me.tab_ops = 0 Then 'first tab clicked
Me.OPERATIONSops.SourceObject = "OPERATIONSops"
Me.OPERATIONSgascom.SourceObject = ""
Me.OPERATIONSdiesel.SourceObject = ""
Me.OPERATIONScrude.SourceObject = ""
Me.OPERATIONSutilities.SourceObject = ""
Me.OPERATIONSoil.SourceObject = ""
Else
If Me.tab_ops = 1 Then 'second tab clicked
Me.OPERATIONSops.SourceObject = ""
Me.OPERATIONSgascom.SourceObject = "OPERATIONSgascom"
Me.OPERATIONSdiesel.SourceObject = ""
Me.OPERATIONScrude.SourceObject = ""
Me.OPERATIONSutilities.SourceObject = ""
Me.OPERATIONSoil.SourceObject = ""
Else
If Me.tab_ops = 2 Then 'third tab clicked
Me.OPERATIONSops.SourceObject = ""
Me.OPERATIONSgascom.SourceObject = ""
Me.OPERATIONSdiesel.SourceObject = "OPERATIONSdiesel"
Me.OPERATIONScrude.SourceObject = ""
Me.OPERATIONSutilities.SourceObject = ""
Me.OPERATIONSoil.SourceObject = ""
Else
If Me.tab_ops = 3 Then 'fourth tab clicked
Me.OPERATIONSops.SourceObject = ""
Me.OPERATIONSgascom.SourceObject = ""
Me.OPERATIONSdiesel.SourceObject = ""
Me.OPERATIONScrude.SourceObject = "OPERATIONScrude"
Me.OPERATIONSutilities.SourceObject = ""
Me.OPERATIONSoil.SourceObject = ""
Else
If Me.tab_ops = 4 Then 'fifth tab clicked
Me.OPERATIONSops.SourceObject = ""
Me.OPERATIONSgascom.SourceObject = ""
Me.OPERATIONSdiesel.SourceObject = ""
Me.OPERATIONScrude.SourceObject = ""
Me.OPERATIONSutilities.SourceObject = "OPERATIONSutilities"
Me.OPERATIONSoil.SourceObject = ""
Else
If Me.tab_ops = 5 Then 'fifth tab clicked
Me.OPERATIONSops.SourceObject = ""
Me.OPERATIONSgascom.SourceObject = ""
Me.OPERATIONSdiesel.SourceObject = ""
Me.OPERATIONScrude.SourceObject = ""
Me.OPERATIONSutilities.SourceObject = ""
Me.OPERATIONSoil.SourceObject = "OPERATIONSoil"
End If
End If
End If
End If
End If
End If
End Sub
shatteras is offline   Reply With Quote
Old 07-27-2016, 04:08 AM   #11
arnelgp
Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 6,847
Thanks: 55
Thanked 2,183 Times in 2,094 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: unload subforms within a tab of a mainform

to reduced the IFs and End IFs, use SELECT CASE.
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 07-27-2016, 04:13 AM   #12
shatteras
Newly Registered User
 
Join Date: Apr 2016
Posts: 25
Thanks: 5
Thanked 3 Times in 3 Posts
shatteras is on a distinguished road
Re: unload subforms within a tab of a mainform

i'll do that on the next half of my db. this one is only for one department, the other department have more than 5 divisions so the select case will be very helpful. thank you for the help and tip.
shatteras is offline   Reply With Quote
Old 07-27-2016, 05:00 AM   #13
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 9,502
Thanks: 360
Thanked 779 Times in 744 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: unload subforms within a tab of a mainform

I would suggest a possible modification; add this function:-

Code:
Private Function fSetTabCtrlSubFrmSourceToEmptyStr(strTabCtrlName As String) As String
Dim Ctrl As Control

    For Each Ctrl In Me.Controls        'All of the controls in the form
        Select Case Ctrl.ControlType    'What type of control is it?
            Case acSubform              'Is the control a sub-form window?
            
            'Check to see if we are within the correct Tab control
            '(the sub-form window is on a page, the page is on the Tab control. That's why you have to have parent twice)
            If Ctrl.Parent.Parent.Name = strTabCtrlName Then Ctrl.SourceObject = ""
            
        End Select
    Next Ctrl
End Function      'fSetTabCtrlSubFrmSourceToEmptyStr

and then call it like this:-

Code:
Private Sub tab_ops_Click()

Call fSetTabCtrlSubFrmSourceToEmptyStr("tab_ops")

If Me.tab_ops = 0 Then 'first tab clicked
    Me.OPERATIONSops.SourceObject = "OPERATIONSops"
Else
If Me.tab_ops = 1 Then 'second tab clicked
    Me.OPERATIONSgascom.SourceObject = "OPERATIONSgascom"
Else
If Me.tab_ops = 2 Then 'third tab clicked
    Me.OPERATIONSdiesel.SourceObject = "OPERATIONSdiesel"
Else
If Me.tab_ops = 3 Then 'fourth tab clicked
    Me.OPERATIONScrude.SourceObject = "OPERATIONScrude"
Else
If Me.tab_ops = 4 Then 'fifth tab clicked
    Me.OPERATIONSutilities.SourceObject = "OPERATIONSutilities"
Else
If Me.tab_ops = 5 Then 'fifth tab clicked
    Me.OPERATIONSoil.SourceObject = "OPERATIONSoil"
End If
End If
End If
End If
End If
End If
End Sub
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
Old 07-27-2016, 09:20 PM   #14
shatteras
Newly Registered User
 
Join Date: Apr 2016
Posts: 25
Thanks: 5
Thanked 3 Times in 3 Posts
shatteras is on a distinguished road
Re: unload subforms within a tab of a mainform

for the 2nd department, I used your suggested code uncle gizmo, thank you very much. thank you for your help guys. I'm learning a lot

shatteras is offline   Reply With Quote
The Following User Says Thank You to shatteras For This Useful Post:
Uncle Gizmo (07-27-2016)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo Box Requery (MainForm with 4 Subforms) mikejaytlabustro Forms 0 02-12-2015 05:52 PM
Question Help with Subforms on mainform nick941741 General 4 05-13-2009 03:54 AM
Add New Record --> Mainform & Subforms csappo Forms 0 01-10-2008 08:48 PM
Mainform, Switchboard and Subforms hitchhiker Forms 0 03-30-2005 09:15 AM
Mainform with 2 subforms - problems yuccakid Forms 0 05-31-2000 11:43 AM




All times are GMT -8. The time now is 10:32 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