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
54 8656
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.
O.K. again I am feeling generous: :)
At the top of your forms module you should have something to the effect of: - Option Compare Database
-
Option Explicit
-
Dim Beer As Integer
-
-
Private Sub MveForwrdJack_Click()
-
If Me!TabCtl1.Pages.Count > Beer + 1 Then
-
Beer = Beer + 1
-
Me!TabCtl1.Pages(Beer).SetFocus
-
End If
-
End Sub
-
-
Private Sub MveBackDaniels_Click()
-
If Beer > 0 Then
-
Beer = Beer - 1
-
Me!TabCtl1.Pages(Beer).SetFocus
-
End If
-
End Sub
-
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!
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!
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
lol! I agree :)
Well it's not working for me. I named my tab control TabCtl_Survey so my code looks like this: - Private Sub btnAddReplicate_Click()
-
If Me!TabCtl_Survey.Pages.Count > Beer + 1 Then
-
Beer = Beer + 1
-
Me!TabCtl_Survey.Pages(Beer).SetFocus
-
End If
-
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?
Is TabCtl_Survey located on the same form as the buttons and are the buttons on the form itself or on the tabs?
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.
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. :)
I would prefer to have the button inside the form - it looks a little cleaner.
Inside the sub form that is on the control? - Private Sub btnAddReplicate_Click()
-
If Me.parent!TabCtl_Survey.Pages.Count > Beer + 1 Then
-
Beer = Beer + 1
-
Me.parent!TabCtl_Survey.Pages(Beer).SetFocus
-
End If
-
End Sub
?
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.
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. -
Me.parent!TabCtl_Survey.Pages(0).SetFocus
-
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 -
Private Sub btnAddReplicate_Click()
-
Me!TabCtl_Survey.Pages!pgeReplicate.SetFocus
-
End Sub
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?
Parent darn it Parent lol :) Did you miss that earlier? -
Private Sub btnAddReplicate_Click()
-
Me.parent!TabCtl_Survey.Pages!pgeReplicate.SetFocus
-
End Sub
Get this one and i'll hand you a cold one. :) Uh in an hour though almost 5:00 here.
OpenArgs shouldn't have an effect on it unless they are in the same subroutine. We can look at that next.
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: - 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: -
DoCmd.GoToRecord acDataForm, "frm_Survey", acNewRec
-
DoCmd.GoToControl "txt_SurveyNum"
Now I'm not sure how to set the path.
-
Me.Parent!TabCtl_Survey.Pages!Page14.SetFocus
-
DoCmd.GoToRecord , , acNewRec
-
DoCmd.GoToControl "Field1"
-
Simple as that.
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 - Private Sub btn_StartTrawl_Click() 'Trawl button
-
On Error GoTo Err_btn_StartTrawl_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "frm_SurveyTabs"
-
DoCmd.OpenForm stDocName, , , , , , "TR"
-
-
DoCmd.Close acForm, "frm_MainMenu"
-
-
Exit_btn_StartTrawl_Click:
-
Exit Sub
-
-
Err_btn_StartTrawl_Click:
-
MsgBox Err.Description
-
Resume Exit_btn_StartTrawl_Click
-
-
End Sub
And on frm_Survey (which lives on page one of the tab control) I have -
-
Private Sub txt_SurveyNum_AfterUpdate() 'Concatenate after update of suvery number
-
If Not IsNull(Me.OpenArgs) Then
-
Me.Survey_Num = Me.OpenArgs & Me.txt_SurveyNum
-
End If
-
End Sub
-
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.
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: -
Private Sub txt_SurveyNum_AfterUpdate() 'Concatenate after update of suvery number
-
If Not IsNull(Me.OpenArgs) Then
-
Me!frm_Survey.form!Survey_Num = Me.OpenArgs & Me!frm_Survey.form!txt_SurveyNum
-
End If
-
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. :)
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! :)
(and it didn't work by the way) :(
Why not? Oh heck wait a sec. (Beer on the brain). - Private Sub txt_SurveyNum_AfterUpdate() 'Concatenate after update of suvery number
-
If Not IsNull(Me.parent.OpenArgs) Then
-
Me!Survey_Num = Me.Parent.OpenArgs & Me!txt_SurveyNum
-
End If
-
End Sub
-
Better?
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!
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 - 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 - 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
Oh yeah, and I have this on frm_Survey - Private Sub Form_Load()
-
DoCmd.GoToRecord , , acNewRec
-
End Sub
But that doesnt' seem to work either.
Oh yeah, and I have this on frm_Survey - Private Sub Form_Load()
-
DoCmd.GoToRecord , , acNewRec
-
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.
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.
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.
Sorry, I've never done that before. Can you explain how?
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.
I always wondered what that red dot did. :)
But what will it tell me? How will I know if it's firing or not?
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.
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?
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.
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.
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.
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? ;)
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).
Wise words, let me guess is your name Bugs as in Bugs Bunny? ;)
Are you implying my coding is horribly flawed? ;)
Awesome I will take a look. I hope the copy/paste of the controls will solve my problem!
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.
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?
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.
Are you implying my coding is horribly flawed? ;)
It has definitely been a long day I JUST NOW realized what you meant Bugs! :)
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
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. :)
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Hypo |
last post by:
I added a 'Back' button to my page, and wrote 'OnClick'
code something like this:
Response.Write("<script>history.go(-" +
iDepthIndex.ToString() + ");</script>");
But, it dosnt work! Effect...
|
by: Justnew |
last post by:
I have a button in my webform.aspx
And I have a htm document or page. What I want is that when I click on
the button I want to display the htm page. In other words it is just a
back button
...
|
by: socasteel21 via AccessMonster.com |
last post by:
I have a spreadsheet that has 3 tabs each of the worksheets is setup exactly
like a cooresponding table in Access. I created a button that should import
each tab to a new table and then append...
|
by: Alex |
last post by:
Hello,
I hope I can explain this properly. I'm writing an application with a
tabbed-based navigation, and a form which gets filled out by users will
be split into 5 subtabs. What I need is...
|
by: =?Utf-8?B?RWRC?= |
last post by:
This very nice feature in VS2003 seems to have been omitted in VS2005. I see
the bookmarks, but it's not the same. Am I just not seeing where it is in
VS2005?
|
by: samueltilden |
last post by:
I started a new job and the version of Visual Studio 2005 that I am
now using does not have the Navigate Backward Button nor the Navigate
Forward Button in the Standard Toolbar, and they are not...
|
by: ebyogendra |
last post by:
Hello friends.
Am new to this forum. Am having some doubts on TabbedPane. Thing is i need to insert "Close button" on each tab as and when new tabs are included in TabbedPane.
Please any help...
|
by: evenlater |
last post by:
I have an .accde file with custom ribbons and with "Allow Full Menus"
set to False, but the Office Button menu still gives the user the
ability to create a new Access database, or -- much worse --...
|
by: Tom |
last post by:
How do we get out of the browser infinite loop quicksand when we navigate
to web pages designed to lock us in and force us to hit the "pay me" button
(whatever they want to force you to do)?
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |