469,626 Members | 1,369 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

button to navigate tabs?

AccessIdiot
493 256MB
I've searched but can't find this. What kind of code do you put on a button to go to a different tab? I'm not sure how to address a tab - by the "caption" name you give it? Or by some kind of control name?

And another question - how do you reference controls on a tab?

thanks
Apr 12 '07 #1
54 7878
Denburt
1,356 Expert 1GB
Tab Control referencing.

Accessing Tabs on a Tab Control


Give me time I'll be back with more :)
Apr 12 '07 #2
Rabbit
12,516 Expert Mod 8TB
The controls on a tab are referenced the same way as if the tabs didn't exist, nothing special.

The controls of the tab have different methods which is explained in the link provided by Denburt.
Apr 12 '07 #3
Denburt
1,356 Expert 1GB
O.K. again I am feeling generous: :)

At the top of your forms module you should have something to the effect of:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Dim Beer As Integer
  4.  
  5. Private Sub MveForwrdJack_Click()
  6. If Me!TabCtl1.Pages.Count > Beer + 1 Then
  7. Beer = Beer + 1
  8. Me!TabCtl1.Pages(Beer).SetFocus
  9. End If
  10. End Sub
  11.  
  12. Private Sub MveBackDaniels_Click()
  13. If Beer > 0 Then
  14. Beer = Beer - 1
  15. Me!TabCtl1.Pages(Beer).SetFocus
  16. End If
  17. End Sub
  18.  
If others will be looking at your project code you may not want to use Beer as a variable or my control names :) You could always use something like PMS, Darn, Sht, or a lot of other funny stuff but it can get a little confusing lol, really though I usually use TBCtrl or something to that effect so you know why it is there. But they all work for me. :) I am off work and out the door so I have one thing on my mind, I think you can guess what that is!
Apr 12 '07 #4
AccessIdiot
493 256MB
lol.

No one is going to see this beast except me I think. Unless of course the new person we're looking to hire is an Access/VBA expert and takes this project over from me, in which case he/she better appreciate the humor. :)

I'm gonna use it anyway . . .

As usual - thanks so much for all the help, you guys are the best!
Apr 13 '07 #5
AccessIdiot
493 256MB
Tab Control referencing.

Accessing Tabs on a Tab Control


Give me time I'll be back with more :)
*Bookmarked*
Apr 13 '07 #6
Denburt
1,356 Expert 1GB
Glad I could help but I just reread my code and I really don't like the Beer -1 it should always be Beer + 1 :) j/k
Apr 13 '07 #7
AccessIdiot
493 256MB
lol! I agree :)

Well it's not working for me. I named my tab control TabCtl_Survey so my code looks like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnAddReplicate_Click()
  2. If Me!TabCtl_Survey.Pages.Count > Beer + 1 Then
  3. Beer = Beer + 1
  4. Me!TabCtl_Survey.Pages(Beer).SetFocus
  5. End If
  6. End Sub
but I"m getting the error message:
Run-time error '2465': Microsoft Office Access can't find the field 'TabCtl_Survey' referred to in your expression."
It's not a field?

Note that I built two forms: frm_Survey and frm_Replicate, then created a blank third form (frm_SurveyTabs), created a tab control, and dragged-n-dropped the two forms into the two pages of the tab control.

So maybe I need to refer to the form name and not the tab control name? Or I need to refer to tab control name, then form name?
Apr 13 '07 #8
Denburt
1,356 Expert 1GB
Is TabCtl_Survey located on the same form as the buttons and are the buttons on the form itself or on the tabs?
Apr 13 '07 #9
Denburt
1,356 Expert 1GB
Just for clarification
So maybe I need to refer to the form name and not the tab control name? Or I need to refer to tab control name, then form name?
Simply put no.

The code I supplied had a main form with a tabcontrol and two buttons on it. The buttons were on the main form itself and simply cycles through each of the tab control pages. If you have another idea or are trying a different strategy let me know and we will see what we can do.
Apr 13 '07 #10
AccessIdiot
493 256MB
Well originally I had it on the frm_Survey inside the tab control (frm_Survey was dragged-n-dropped onto the tab page so I guess it's a form within a tab right? Instead of a tab page with controls on it).

But I just tried moving the button outside of the form and onto the tab page itself and I still get the same error. I would prefer to have the button inside the form - it looks a little cleaner. :)
Apr 13 '07 #11
Denburt
1,356 Expert 1GB
I would prefer to have the button inside the form - it looks a little cleaner.
Inside the sub form that is on the control?

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnAddReplicate_Click()
  2. If Me.parent!TabCtl_Survey.Pages.Count > Beer + 1 Then
  3. Beer = Beer + 1
  4. Me.parent!TabCtl_Survey.Pages(Beer).SetFocus
  5. End If
  6. End Sub
?
Apr 13 '07 #12
AccessIdiot
493 256MB
Well there will be two buttons - one on the form to go the tab page that contains the subform and one one the subform to return to the tab page that contains the form. Basically, go back and forth from one tab page to the other but the button is inside the form or subform that is on that page.
Apr 13 '07 #13
Denburt
1,356 Expert 1GB
Girl you have had way to much beer so I am taking it away! lol

Simply use the page number you want to go to or use the page name as in the example you have bookmarked the only difference is that if we are in a sub form we need to reference the parent form since that is where the tab control resides.
Expand|Select|Wrap|Line Numbers
  1. Me.parent!TabCtl_Survey.Pages(0).SetFocus
  2.  
Apr 13 '07 #14
AccessIdiot
493 256MB
Darn, I like beer. Maybe I'll go back and rename all my controls after my favorite snacks. Hmm, must be lunchtime. :P

Anyway, I have tried several perturbations of the code and none of them work. :(

I have the button on the form that is within page 1 of the tab control. Another button will be in a subform on page 2 of the tab control.

Tab Control name: TabCtl_Survey
Page 1 Caption: Survey
Page 1 Name: pgeSurvey
Page 2 Caption: Replicate
Page 2 Name: pgeReplicate
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnAddReplicate_Click()
  2. Me!TabCtl_Survey.Pages!pgeReplicate.SetFocus
  3. End Sub
Apr 13 '07 #15
AccessIdiot
493 256MB
You know I'm wondering if maybe the fact that I'm trying to pass an OpenArgs (which isn't working now that I have the form inside a tab) is the problem here?

I have a Main Menu form that has three buttons on it. All three buttons open the same form (the one with the tab control) but a different OpenArgs value is passed depending on what button was pushed.

Could that be what's holding things up?
Apr 13 '07 #16
Denburt
1,356 Expert 1GB
Parent darn it Parent lol :) Did you miss that earlier?

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnAddReplicate_Click()
  2. Me.parent!TabCtl_Survey.Pages!pgeReplicate.SetFocus
  3. End Sub
Get this one and i'll hand you a cold one. :) Uh in an hour though almost 5:00 here.
Apr 13 '07 #17
Denburt
1,356 Expert 1GB
OpenArgs shouldn't have an effect on it unless they are in the same subroutine. We can look at that next.
Apr 13 '07 #18
AccessIdiot
493 256MB
Booyah, hand it over. lol.

I totally thought that the parent was only for the subform to refer back to the form!

Sorry sorry sorry - and thanks of course.

So I'm still confused about how to refer to a control on the form - do I have to use the name of the tab control in the path? Like let's say when I go from the Replicate subform page back to the Survey form page I put this on the button:
Expand|Select|Wrap|Line Numbers
  1. Me.Parent!TabCtl_Survey.Pages!pgeSurvey.SetFocus
But I want to open to a new record and set the focus on a textbox called "txt_SurveyNum".

Previously I had this code on the button:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord acDataForm, "frm_Survey", acNewRec
  2. DoCmd.GoToControl "txt_SurveyNum"
Now I'm not sure how to set the path.
Apr 13 '07 #19
Denburt
1,356 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Me.Parent!TabCtl_Survey.Pages!Page14.SetFocus
  2. DoCmd.GoToRecord , , acNewRec
  3. DoCmd.GoToControl "Field1"
  4.  
Simple as that.
Apr 13 '07 #20
AccessIdiot
493 256MB
Rats that was too easy.

Okay now fix my open args problem. You have fifteen minutes. Go.

Just kidding, but I am having trouble with it. It should be simple and was working well before I added tabs. This is the code I have on the button that opens the frm_SurveyTabs which houses the tab control
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_StartTrawl_Click()                                                  'Trawl button
  2. On Error GoTo Err_btn_StartTrawl_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "frm_SurveyTabs"
  8.     DoCmd.OpenForm stDocName, , , , , , "TR"
  9.  
  10.     DoCmd.Close acForm, "frm_MainMenu"
  11.  
  12. Exit_btn_StartTrawl_Click:
  13.     Exit Sub
  14.  
  15. Err_btn_StartTrawl_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_btn_StartTrawl_Click
  18.  
  19. End Sub
And on frm_Survey (which lives on page one of the tab control) I have
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub txt_SurveyNum_AfterUpdate()                                                    'Concatenate after update of suvery number
  3. If Not IsNull(Me.OpenArgs) Then
  4.     Me.Survey_Num = Me.OpenArgs & Me.txt_SurveyNum
  5. End If
  6. End Sub
  7.  
Where Survey_Num is a field in my table that needs to get filled in and txt_SurveyNum is an unbound field.

Ideas? I'm guessing the problem lies in the use of frm_SurveyTabs and frm_Survey. The fields are actually on frm_Survey but frm_Survey lives on page one of the tab control on frm_SurveyTabs so I'm not sure which to reference. I think the DoCmd.Open has to refer to frm_SurveyTabs but don't I want the OpenArgs to be available to frm_Survey since that is what the textbox to concatenate is on?

Argh! I'm confusing myself now.
Apr 13 '07 #21
Denburt
1,356 Expert 1GB
ROFL heck if your confused then what do you think I am... I REALLY want that beer now.
O.K. I was going to try and escape from here early we have the French Quarter Festival :) Can you say PARTY!

Serious though I can hang for a few more min:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txt_SurveyNum_AfterUpdate()                                                    'Concatenate after update of suvery number
  2. If Not IsNull(Me.OpenArgs) Then
  3.     Me!frm_Survey.form!Survey_Num = Me.OpenArgs & Me!frm_Survey.form!txt_SurveyNum
  4. End If
  5. End Sub
To easy give me something difficult would you. NOT Just respond back telling me you got it (I know you will) so I can go get that beer and listen to some music. :)
Apr 13 '07 #22
AccessIdiot
493 256MB
Ack! Don't let me hold you up! It's Friday afternoon for goodness sake man. This can wait 'til Monday. I'll try it out and post back but don't stick around!

Thanks and happy weekend! :)
Apr 13 '07 #23
AccessIdiot
493 256MB
(and it didn't work by the way) :(
Apr 13 '07 #24
Denburt
1,356 Expert 1GB
Why not? Oh heck wait a sec. (Beer on the brain).

Expand|Select|Wrap|Line Numbers
  1. Private Sub txt_SurveyNum_AfterUpdate() 'Concatenate after update of suvery number
  2. If Not IsNull(Me.parent.OpenArgs) Then
  3.     Me!Survey_Num = Me.Parent.OpenArgs & Me!txt_SurveyNum
  4. End If
  5. End Sub
  6.  
Better?
Apr 13 '07 #25
AccessIdiot
493 256MB
Yes! Dang it I had the parent in there but forgot it on the If part.

Party on Wayne.
Party on Garth.

Happy happy Friday!
Apr 13 '07 #26
AccessIdiot
493 256MB
I'm back!

Haven't been able to work on this much this week so am only now getting back into it.

The going back and forth between tabs is working wonderfully. But now I have a question as I am still shaky on how to reference forms, tabs, and tabs on forms, lol.

From my main menu (which acts like a switchboard when the db is launched) I press a button to go to the form that has the two tabs on it. I need to have the form that is on the first tab open to a new record. Right now it opens to record one, but doesn't show the info that is already there (if there are multiple records in the underlying table, which there are). Only if you use the navigation buttons to go forward then back does the data in the first record show up. This is bad. If you launch the form and start overwriting the data in that first record, then when you go to the subform the Survey_ID doesn't carry over and it all goes to hell.

SO - I *think* if I can launch the form from the button and have it start on a fresh new record I will *hopefully* solve the problem.

And don't tell me just to use
Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord , , acNewRec
because that doesn't work.

To refresh: the button on the main menu opens "frm_SurveyTabs". On frm_SurveyTabs is a tab control. The first page of the tab control contains "frm_Survey" (which is the one I want to go to a new record) and the 2nd page of the tab control contains "sbfrm_Replicate".

I've also tried
Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord acForm, "frm_Survey", acNewRec 
but I get an error message that "frm_Survey isn't open" or something evil like that.

Any help much appreciated! :)
melissa
Apr 19 '07 #27
AccessIdiot
493 256MB
Oh yeah, and I have this on frm_Survey
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()  
  2. DoCmd.GoToRecord , , acNewRec
  3. End Sub
But that doesnt' seem to work either.
Apr 19 '07 #28
Denburt
1,356 Expert 1GB
Oh yeah, and I have this on frm_Survey
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()  
  2. DoCmd.GoToRecord , , acNewRec
  3. End Sub
But that doesnt' seem to work either.
? That should work, what happened to post #20 you said in post #21 that is was working.

You could set the subform to data Entry but you would need to discern if they want to edit or add records.
Apr 19 '07 #29
AccessIdiot
493 256MB
I know! I don't know what happenned but I can't make it go to a new record. And I do need the users to be able to add/edit data and navigate records. So this is really frustrating.
Apr 19 '07 #30
Rabbit
12,516 Expert Mod 8TB
I don't see any reason for it not to work either. Try setting a break in the Form Load of the subform to see if it even triggers. It should trigger but maybe for some reason it's not triggering in this case.
Apr 19 '07 #31
AccessIdiot
493 256MB
Sorry, I've never done that before. Can you explain how?
Apr 19 '07 #32
Rabbit
12,516 Expert Mod 8TB
If you put the text editor cursor on the line and press F9, it'll highlight the line in red and put a red dot on the left bar. When the code runs, once it hits the red line it'll stop there before executing the statement. F8 steps through the code. F5 continues the code without stopping until it hits another break.
Apr 19 '07 #33
AccessIdiot
493 256MB
I always wondered what that red dot did. :)

But what will it tell me? How will I know if it's firing or not?
Apr 19 '07 #34
Denburt
1,356 Expert 1GB
O.K. Now I see whats going on your main form and the sub form both have the same record source. I am not sure what your best approach would be from here. You have many options and I see why you tried to do it this way but in my opinion your headed down a road you don't want to travel. I would seriously break them up into two forms or just arrange it so you have the main form with 1 sub form control. I am sure if I spent enough time I could devise a way to synchronize the two tables but since they are both sub forms you would need to change the record source etc. they have a 1 to many relationship and there aren't that many controls on here so there is no reason you can't have a main form and several sub forms.

I had an idea but went bust half way through, I am trying to stay within the scope of what you want accomplished I removed the survey as a subform and put all controls right on the tab control, then I quickly realized that you have no record navigation on the replicate sub form. This will prevent anyone from viewing anything but the first record no matter how many replicates are there. I am sending it back so you can see the direction I was taking and hopefully you can get some use from it. Also look at tbl_ReplicateDenBurt in design view and see the changes I made there.

tbl_ReplicateDenBurt:

Replicate_ID PK Defined now and Index is set at yes no Dups.
Survey_ID FK Defined now
Replicate_Num Indexed since it looks like a field you may use to search at some time
Bird_Activity Indexed since it looks like a field you may use to search at some time

Good Luck let me know how it goes.
Apr 19 '07 #35
AccessIdiot
493 256MB
Wait that's weird. Why would frm_SurveyTabs have any kind of record source?

When making the tabs I thought it would be much easier to drag and drop an existing form onto each page of the tab. So I created a blank form, created the tab control, then dragged frm_Survey onto page 1 and sbfrm_Replicate onto page 2. I don't really care about frm_SurveyTabs, it's just a form that holds the tab control.

So why is Access giving it a Record Source? And can I get rid of it?
Apr 19 '07 #36
Denburt
1,356 Expert 1GB
So why is Access giving it a Record Source? And can I get rid of it?
I don't know but it jumped in there somehow. That is how/why your sub forms are linked to the main form, if they are not linked to the main form then they will not be/stay synchronized.

Take a look at what I did, if you really want to have them both as sub forms your going to be in for a lot more work trying to sync them up.

Either way you will need navigation buttons for the replicate sub form or you will never see anything but the first record.
Apr 19 '07 #37
Rabbit
12,516 Expert Mod 8TB
I always wondered what that red dot did. :)

But what will it tell me? How will I know if it's firing or not?
This may be moot at this point but if the visual basic editor pops up and highlights the line, that means the event triggered. If not, that means it didn't.

You can also use it to make sure the code is doing what it's supposed to be doing by stopping execution at a certain point and then stepping through the code one line at a time.
Apr 19 '07 #38
AccessIdiot
493 256MB
Thanks Rabbit, it did highlight and now I know what's it doing.

Denburt I guess I had no idea that by dragging and dropping the frm_Survey onto the tab control I was, effectively, making it a subform of frm_SurveyTabs. I had no intention of doing that. Having frm_Replicate be a subform of frm_Survey is enough!

So can I fix it by copying and pasting the controls from frm_Survey onto page one of the tab control instead of just dragging and dropping the whole form? I think that having tabs is easier/better than having two forms but I want Replicate to be a subform of Survey and thats it.
Apr 19 '07 #39
Denburt
1,356 Expert 1GB
This may be moot at this point but if the visual basic editor pops up and highlights the line, that means the event triggered. If not, that means it didn't.

You can also use it to make sure the code is doing what it's supposed to be doing by stopping execution at a certain point and then stepping through the code one line at a time.
Wise words, let me guess is your name Bugs as in Bugs Bunny? ;)
Apr 19 '07 #40
Denburt
1,356 Expert 1GB
So can I fix it by copying and pasting the controls from frm_Survey onto page one of the tab control instead of just dragging and dropping the whole form? I think that having tabs is easier/better than having two forms but I want Replicate to be a subform of Survey and thats it.
Yes you can but you will probably want to look at the VBA I made some nifty changes to keep your colors in Sync depending which tab you are in etc. (Still may need a little touch up).
Apr 19 '07 #41
Rabbit
12,516 Expert Mod 8TB
Wise words, let me guess is your name Bugs as in Bugs Bunny? ;)
Are you implying my coding is horribly flawed? ;)
Apr 19 '07 #42
AccessIdiot
493 256MB
Awesome I will take a look. I hope the copy/paste of the controls will solve my problem!
Apr 19 '07 #43
Denburt
1,356 Expert 1GB
Awesome I will take a look. I hope the copy/paste of the controls will solve my problem!
I am sure it will just remember the other considerations i mentioned.


No Rabbit, nothing wrong with your coding just that Bugs was one clever Rabbit.
Apr 19 '07 #44
AccessIdiot
493 256MB
You guys are punny. :D

Denburt I see that in the Replicate table you made several fields into one giant primary key. Can you explain the reasoning behind that?
Apr 19 '07 #45
Denburt
1,356 Expert 1GB
You guys are punny. :D

Denburt I see that in the Replicate table you made several fields into one giant primary key. Can you explain the reasoning behind that?
Did I? I was moving stuff around and trying to rush If I did, it wasn't done purposefully.
Apr 19 '07 #46
Denburt
1,356 Expert 1GB
Are you implying my coding is horribly flawed? ;)
It has definitely been a long day I JUST NOW realized what you meant Bugs! :)
Apr 19 '07 #47
AccessIdiot
493 256MB
Did I? I was moving stuff around and trying to rush If I did, it wasn't done purposefully.
Yes in tbl_ReplicateDenburt there are several primary keys. Was that an error? lol
Apr 19 '07 #48
Denburt
1,356 Expert 1GB
Dim Beer as Hops (get it)
Beer = "Jack Daniels"

"I'm out for now time for a " & beer!

Hey looks like I see some Bugs. :)
Apr 19 '07 #49
Rabbit
12,516 Expert Mod 8TB
I use a composite primary key sometimes. For example Admission Date and ID Number. Multiple admissions per ID Number but no more than one admission per ID number per day.
Apr 19 '07 #50

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Hypo | last post: by
5 posts views Thread by Justnew | last post: by
1 post views Thread by socasteel21 via AccessMonster.com | last post: by
2 posts views Thread by =?Utf-8?B?RWRC?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.