How to dynamically open a form within a tab? - vba

I have a parent form with a tab control. The tabs show subforms. Data shown in the parent form is general details about residential property, such as address, etc. In the tabs, the subforms show data that is county-specific and exhaustive, like garage square footage and on and on.
There are 6 tabs with a static subform i.e. that tab always shows the same subform. I'd like the 7th tab to dynamically open a subform depending on which county the property exists in. That is, based on the value of a control (Me.Form.County), populate this 7th tab with the corresponding subform for the highly specific details for that county.
(No, it's not desirable to make one subform that could render data for any county; it'd be huge, relatively. One form per county is the requirement.)
It'd be nice if there's a way to act on the event of clicking on the 7th tab to then open the county-specific subform, though I don't see OnClick for a tab. If there's a way that's close to that simple for the user that'd be fine too.

You can use the Subform.SourceObject property to change which form is displayed in a Subform control.
https://learn.microsoft.com/en-us/office/vba/api/access.subform.sourceobject
You can use the Change event of the Tab Control to respond to the user switching tabs and display the correct subform if they are looking at the desired tab.
Private Sub tabCounty_Change()
If tabCounty.Pages(tabCounty.Value).Caption = "County Info" Then
subCountyInfo.SourceObject = "frmCounty" & Me.Form.County
End If
subCountyInfo.Form.Requery
End Sub

Related

Changing a control's value in a particular Tab of a TabStrip

Basically, I have a multipage for different departments of information called mpageTabsMain.
Inside each page of the multipage is a tabstrip, that contains tabs that represents different people.
What i'm doing for testing right now is using a button click to fill in a textbox's text on my 2nd page of the multipage.
mpageTabsMain.Pages(1).TextBox1.Text = "test"
However, what this does is it fills in the TextBox1's text for every Tab (person) in the TabStrip.
How do I refer to a particular tab (person)'s control in a TabStrip so that only that one is filled?
Thanks.
1) You can't have the same control names within a UserForm.
2) If you want to handle different controls for each page (e.g. TextBox1 on page1, TextBox2 on page2) you should use a Multipage control and maybe this would be the better choice for your requirements.
3) A Tabstrip control makes sense for pages with a similar or identical layout, but uses ONE set of controls only. So if you assign a value to your TextBox1.Text property without further conditions
(i.e. distinguishing between the different kinds of pages) you'll get the same text for the same TextBox1 control independantly of which page you are addressing. Though a Tabstrip can possibly
facilitate to write comparable code for only a few controls (distinguishing at which page you are), it could be the harder part to code.
Addendum (refers to comment below)
OK, you are using a TabStrip within a Multipage and apparently you want to display a tabstrip tab for every person. (BTW, I wouldn't do that, you could just change the tab name dynamically, but that isn't the question).
There is no more than one unique TextBox1 control in the whole UserForm. As TextBox1 is a unique Name, and instead your long code line it's sufficient to assign a string value via Me.TextBox1.Text = "test content for Person A" referring to a current tab view of Person A or TextBox1.Text = "test content for Person B" according to another tab view and another tab value. But it's the same TextBox1 in any case. Me stands for the UserForm itself inside the Userform code module.
You only 'fake' the view to this text (control) depending on the tab situation and are responsible to write it back properly or save it according to the actual tab view :-;

How to stay at the top of form on form load?

I am facing a problem with multiple forms.
When loaded, it doesn't show the tabs at the top which are part of the form and requires the user to scroll up.
I have done research. It may be related to the .SetFocus property.
Private Sub Form_Load()
Forms!frmEnrolementForm.Tab ("tabCtl0.SetFocus")
End Sub`
As I understand, user doesn't see the top part of window with tabs of tabcontrol. If so, reduce the size of tab control and whole window in order to fit in window on PC with minimal screen resolution. Also you can open desired tab page using code like
Forms!frmEnrolementForm.Page1.SetFocus
Here Page1 - is name of tabpage, not tab control. SetFocus is object method, not property.
It depends on the layout of your form, but you might be able to solve the issue by changing the "Tab Order" settings for the form.
It's under Form design tools > design > Tab Order, and you want the top/first items on your form to be at the top of the list. Ideally I'd say put all the items in a sensible order (e.g. starting with the top left and ending with the bottom right) for a good user experience, but the first item is the one that affects where the form opens.
Mine was opening in the middle of the page because my sub-form was set as the top item in the tab order, but I changed it to a button at the top of my form and now it always opens at the top.
I got this from user NeoPa in this forum answer.

MS Access VBA to set current selection/record to null on a continuous form

I have a form with a subform that is a continuous form. I have a tab control that displays information related to the record selected in the continuous form; the tab control displays as soon as a record is selected/clicked. That all is grand.
However, after the user updates information in the tab control and clicks a button, I want to hide the tab control until a record is actually clicked on the continuous form.
What is currently happening is that the first record in the continuous subform is selected and I'd like for no record to be selected.
Is there a way to set the current record/selection of a continuous form to nothing or null? I've tried setting the bookmark on the continuous form to null in the button click event using Parent.SubApptList.Form.Bookmark = Null and that does not work for me.
Seems like it should be easy, but I can't figure it out.
After the button click event could you set focus to the parent form? Doing this would force the user to click on a record. Maybe I'm not fully understanding exactly what you're trying to do but if all you want is for nothing to have focus after a button event then that's the route I would take. That's assuming you don't having any on focus events for thr main form.

Access forms and sub-forms

I am building a database on MS 2003. I have one form which calls for a series of options. This form is based on the table "Categories" which is linked to the main table by Customer ID.
Now, both forms appear together on the same screen, what I am trying to do is have the person select one or more of the categories and in pressing a command button then those categories which were selected will show its respective forms. The forms are invisible until selected and until the command button is pressed.
Since they are two different forms (categories in one) and the entry form on another, How do I program the command button to make the entry form visible FROM the other form?
The sub-form is located in a tab. I dont want to show it as a pop-up but to become visible within the tab where it's located
If the form is open but invisible then you can refer to it as a member of the forms collection and make it visible:
forms("myForm").Visible = true
If the form isn't open then get its name from the AllForms collection of the project and then use the OpenForm method:
docmd.OpenForm currentproject.AllForms("myForm").Name, acNormal
Pseudologic: you are basically going to want to set the Visible property with all of your forms to False during the form's Open event. You should place this Visible = False code in a separate subroutine so that the code structure can be called during other events too. (For example you may want to provide a Reset button so that the user can reset the form, or trigger the "set false" code when a new customer id is selected.) Then with every selected category you would set its associated form property visible by setting Visible = True.

Option Group frame: can I add text boxes that are part of the frame instead of rad button options?

Ok so this maybe a simple/silly question but I don't know so here goes:
In access let's say I want to have a frame control, so I click the option group button and add it to the desgin surface. However, I am not wanting to use this as a option group with radio button selection, instead I would like to add text boxes instead the frame, so that when I reference the frame, it references every control instead of it, hence the text boxes, cbo boxes, etc.....just as it would if they were radio option selections.
So can you do this?
I want whatever controls I add inside the frame to be easily referenced (i.e. make all controls visible just by using frameExample.visible = true) so that I can build my own tab control groupings.....
can this be done?
Thanks!
EDIT:
What I am trying to accomplish is having a form that includes a collection of controls (input controls - cbo boxes, text boxes, etc), that serve as the Main record information. These are saved to a table via an INSERT statement on button_click because this form is unbound.
Next I have 8 categories that are relative per each main record (and data that goes along with it). Each of these categories could have a sub form area and a button click that bring it's relative form into the sub form area. These sub forms would be unbound as well as I would just save data via SQL statement. So i know I could accomplish this by running the insert statement from the parent form, on the main collection control's data that would create the KeyID number, then run a SQL statement that would turn around and load that KeyID number right back onto the page in a hidden text box.
Then when I click one of the sub forms and load its relative collection of controls, I could then save that data along with KeyID for each of these sub-forms/tables.
SO......
I was wondering if instead you could define these controls as a collection so that you could hide and make visible all the ones you need on button clicks and avoid the need for additional forms (subs). I know that if a user enters data into a text box, and then somewhere along the way that box becomes hidden, the data still exists in it and still ends up in the SQL statement....
So I want all these controls to exist on the same form, but I thought what is I could encapsulate them into a frame like an option group, then I could call the frame and all the relative controls would be called up (made visible) as needed.
Sorry for the long explanation but I thought it would help.
I do not think you can do it with an Option Group, but what you are describing is pretty much a subform, yesno?
Some examples of hiding the tab control from an app that went live in March 1998:
Tab driven by transparent command buttons over labels styled to look like colored command buttons:
Same approach, more buttons:
In this case, fake colored command buttons don't drive the tab, but insted show/hide the tab and a subform. In this case, the tab is actually driven by the listbox:
A view of when the tab is hidden and the subform revealed. The listbox drives navigation within the subform, which has a visible tab on it:
So, there's a lot that can be done without showing the tab control.