Disable Some Tab Pages on adding new record (1 Viewer)

slansh

Registered User.
Local time
Yesterday, 23:56
Joined
Nov 24, 2011
Messages
22
Hi Guys,

:)

I'm kinda new here and so as to ms access 2010 so I hope you can help me out.

How to disable some tab pages while adding new record?
My form has 4 tab pages the first 2 are for users details information and the other two are for the qualification and courses. I need to disable the last two tab pages during adding of new user records 'coz it cannot add the datas on qualification and course tables yet since the id of the user is not yet been added/save.
I kinda confused how to do this.... I hope you guys can help me out....

Thanks
 

vbaInet

AWF VIP
Local time
Today, 07:56
Joined
Jan 22, 2010
Messages
26,374
Is the first page based on a subform or is it based on the record source of the main form?
 

slansh

Registered User.
Local time
Yesterday, 23:56
Joined
Nov 24, 2011
Messages
22
Hi

Thanks for the reply...

The first two pages are record source of the main form where you input new learner information datas and the last two pages are subforms for their list of qualifications & courses(on separate tables)....

regards
 

vbaInet

AWF VIP
Local time
Today, 07:56
Joined
Jan 22, 2010
Messages
26,374
Good!

So in the On Current event of the main form you can use something like this:
Code:
Me.[COLOR=Red]TabControlName[/COLOR].Pages("[COLOR=Red]Page3[/COLOR]").Enabled = Not Me.NewRecord
where Page3 is the name of the third page and TabControlName is obviously the name of the tab control. Substitute them for the right names and use the same code for page 4.
 

slansh

Registered User.
Local time
Yesterday, 23:56
Joined
Nov 24, 2011
Messages
22
Cool....
That really work well.....

How about if I add a popup message when they a page 3 and 4 is click during adding of new record? So I can notify the user that it needs to save the record first before they can use the page 3 and 4......


I'm so lost every time it has to do with with macros event function with vb
Thanks a lot for that first one....
Thank in advance for the second one... :)
 

vbaInet

AWF VIP
Local time
Today, 07:56
Joined
Jan 22, 2010
Messages
26,374
Do this on the On Change event of the Tab Control. Not the page, but the Tab Control.

The steps are:

1. Check if Me.Dirty is True
2. If it is, show the Msgbox
3. Then, Set Focus back to the page they were on.
 

slansh

Registered User.
Local time
Yesterday, 23:56
Joined
Nov 24, 2011
Messages
22
I kinda don't get it on how to do the steps...
Should I be coding that on code builder or can be on macro?

I hope you can be more specific 'coz I'm kinda just too new to ms access 2010...

Thanks
 

vbaInet

AWF VIP
Local time
Today, 07:56
Joined
Jan 22, 2010
Messages
26,374
Do you know how to write an IF statement? And do you know how to write an Msgbox?
 

slansh

Registered User.
Local time
Yesterday, 23:56
Joined
Nov 24, 2011
Messages
22
Sad to say I kinda don't know how to do that on access nor msgbox..... :( :(
 

vbaInet

AWF VIP
Local time
Today, 07:56
Joined
Jan 22, 2010
Messages
26,374
Sad to say I kinda don't know how to do that on access nor msgbox..... :( :(
Have you tried searching the Internet for the keywords, "IF statement VBA" and "Msgbox VBA"?

Have a read and let me see what you try and if you don't get it I will show you how.
 

slansh

Registered User.
Local time
Yesterday, 23:56
Joined
Nov 24, 2011
Messages
22
Okay I tried :( :confused:
I know how to do if statements but not with VBA. Well honestly I don't know VBA at all.... but I tried anyway and followed your instruction.... I placed a code something like this...

Code:
Private Sub LearnerTab_Change()
If Me.Dirty = True Then
MsgBox "You can add Qualification and Training History record only after you have save this form"
Me.LearnerTab.Pages("GeneralInfo_CoursePage").SetFocus
End If
This one does not work or make any reaction at all when I click the 3rd tab. It should suppose to message me that "".
Sorry if this code doesn't make sense but it's a noob trying figure out a way.
:eek::eek:
 
Last edited:

vbaInet

AWF VIP
Local time
Today, 07:56
Joined
Jan 22, 2010
Messages
26,374
Well you did quite well. But two things:

1. Are you sure you were editting the record in the main form before trying to click the third tab?
2. Does your code have an End Sub line? This line should be after End If, it's normally automatically created.

Here's an amendment:
Code:
If Me.Dirty = True Then
    If Me.LearnerTab.Value > 1 Then
        MsgBox "You can add Qualification and Training History " & _
               "record only after you have save this form"
        Me.LearnerTab.Pages("GeneralInfo_CoursePage").SetFocus
    End If
End If
 

slansh

Registered User.
Local time
Yesterday, 23:56
Joined
Nov 24, 2011
Messages
22
Thanks for the reply...:)

But seems the code changes you gave still does not work and no reaction.
1. I placed the code on TabControl like you said on "On Change" event and tested it out on new data to be added. 3rd and 4th were disabled but it doesn't popup msg to warn me.
2. Yes it does have End Sub, just forgot to include.....

I think it lies on the "If Me.LearnerTab.Value > 1" statement, I think this refer to the page index of the tab. Is that right? I'm not sure but I don't know anyhow to make it right....
 

vbaInet

AWF VIP
Local time
Today, 07:56
Joined
Jan 22, 2010
Messages
26,374
The first question I asked you was:
1. Are you sure you were editting the record in the main form before trying to click the third tab?
Your response didn't answer the question.

The form is not dirty when you click the New Record button. The form becomes dirty as soon as type the first character in the new record. So if you want it to fire when the New Record button is clicked, you need to also check if Me.NewRecord is true.

So:
Code:
If Me.Dirty Or Me.NewRecord Then
And yes you are right. That is checking the index. The index starts from 0, so your first page is 0, second page is 1 and so on.
 

slansh

Registered User.
Local time
Yesterday, 23:56
Joined
Nov 24, 2011
Messages
22
Sorry....if that didn't answer your question

Anyway, you're surely genius. It's now working great.... :) :)

Private Sub LearnerTab_Change()
Private Sub LearnerTab_Change()
If Me.Dirty Or Me.NewRecord = True Then
If Me.LearnerTab.Value > 1 Then
MsgBox "You can add Qualification and Training History " & _
"record only after you have save this form"
Me.LearnerTab.Pages("GeneralInfo_CoursePage").SetFocus
End If
End If

End Sub
Thanks a lot.....
I still need a lot of help to finish this project. But I guess I have to open a separate thread for it.... I hope you guys here can help me through it coz I'm just too noob with Access at the moment......
 
Last edited:

vbaInet

AWF VIP
Local time
Today, 07:56
Joined
Jan 22, 2010
Messages
26,374
Happy to hear! :)

Feel free to post a new thread anytime. I'm sure someone on here will be able to assist.

Oh, by the way, why is it that whenever you paste code on here it doesn't have any indents? Is that how you write your code or it's just not showing on the site?
 

slansh

Registered User.
Local time
Yesterday, 23:56
Joined
Nov 24, 2011
Messages
22
:) Thanks, Will definitely open some new thread tomorrow...
Indent seems not showing. My codes actual have indents and so as during I post here by pasting the code but when posted seems all indents are lost....

Anyway... hope to see you again in my new threads... :)
 

vbaInet

AWF VIP
Local time
Today, 07:56
Joined
Jan 22, 2010
Messages
26,374
What you do is write the code tags, copy from your VBA window and paste between the code tags, then post reply.

Maybe you will see me in your new threads ;)

Happy developing!
 

Users who are viewing this thread

Top Bottom