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

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.

Related

How to add existing winform to multiple tabpages

I want to add the same Form in project to five tabpages in TabControl.
This is what i have tried
For i As Integer = 0 To 4
'XtraTabPage instance (DevXpress)
Dim page As New XtraTabPage()
'ExamsTab is the existing form that i want to add tho the page
Dim fm As New ExamsTab
fm.TopLevel = False
fm.Dock = DockStyle.Fill
page.Controls.Add(fm)
fm.BringToFront()
fm.Show()
'Adding the page to the TabControl in Exams_Class
Exams_Class.ExamsTabControl.TabPages.Add(page)
Next
This only adds the form to the last tabpage but doesn't add to others.
If that didn't work I'd try page.Controls.AddRange(fm.Controls) but I'm not in a position to test it.
In the past when I've wanted to keep my code better organized into one form per tab I've:
made a new form
put a tabcontrol on it with a single page, call the control TheTabControl for example
put all the controls into the tab page, put all the events etc in the form code
put a line of code that retrieves the tab:
Public Function GetTab() As TabPage
Return Me.TheTabControl.TabPages(0)
End Function
on the main form, with the one tabcontrol that should contain all the other tab pages, have a code like:
MainTabCobtrol.TabPages.Add(New SomeOtherForm().GetTab())
This way all the controls and their event handlers stay in one form (a good thing) but you can combine them together into one Tab Control on another form. Putting them inside a tab means you can get an idea of how to size it, and you can specify in the designer other things like the tab name etc
From a code organising perspective, it's something the designer can more easily cope with than having all the TabPages in one. Control and all the event handlers etc (makes for a fairly monster form code behind and it doesn't respond well to being split into partial classes)
If you want to add a tab control to the existing form the Document Outline window might be helpful for moving the controls into it with drag and drop. You could also cut all the controls, add a tab and paste, but check the eventbhabdlers are all still wired up afterwards- I find that sometimes this makes them go missing

Dynamically Add Option Buttons to Excel UserFrm with One Event Handler

I have a custom user form in Excel where the number of option buttons is dynamic, depending on what a user selects from a combo box. I have written a script that will add and format those option buttons with appropriate captions, groupname, etc. However, I would like it so that after those buttons are added dynamically, if a user clicks a button from a group just added, then more code will be executed. I am aware that one can create a custom class so that multiple userform controls are handled with one event handler, but I can't figure out how to get this to work with controls that were added dynamically to a form, after the form initialized. I am hoping this question makes sense. Thanks in advance for any help you can offer.

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 :-;

Tab between Excel worksheet cells and form controls

I have a worksheet in Excel 2010 that is protected and used as a form for user-fillable values. The form contains 80 cells to be filled in and two radio button form controls to be selected. The form consists of two pages on the worksheet that are placed side by side horizontally (horizontally is a better user experience than vertically in this situation).
To get tabbing to go through the cells on the first page and then on the second page in the desired order, I used the solution on page 4 of the thread at "http://answers.microsoft.com/en-us/office/forum/office_2007-excel/establishing-enter-order-on-a-protected-sheet/e7a223f3-2dae-4c7b-a37f-1819c68be5dc". This works excellently for regular cells.
The problem is how can I also tab to the radio buttons, which are located about a third of the way through the desired tab sequence? Unfortunately, it's not as easy as just adding the radio button names to the TabOrder array mentioned in the thread.
I've found various threads talking about tabbing between controls, but nothing that solves tabbing from regular cells to form controls, between the form controls, and then back to regular cells.
I'm relatively new to Excel VBA programming and could really use your help. :-)
Thanks!
Don
I can't add a comment, so I have to put this in the answer section even though it is not really an answer: Not sure if this is still an issue for you, but are you using Option Buttons or a Group Box. And are you using Form Controls or ActiveX.
The only thing that I have found that may help is to tab to the group itself, then use the arrow keys: "When you tab to the group, you can use the arrow keys to select the next/previous option." and "2. You can set an accelerator key on each one by adding an ampersand (&) before one letter in the label. For example, if the label's caption is "&Next", it will appear as "Next", and Alt-N will be the keystroke that selects that option. Be careful not to choose a keystroke that opens a menu -- for example, don't pick F, because Alt-F almost alway opens the File menu."
From: http://www.mrexcel.com/forum/microsoft-access/557082-how-idiotic-no-way-tab-stop-option-button-within-group.html

How to click on a position of form or a control automatically?

I'm using Visual Basic 2008 (VB.NET) and I have an old control which have some buttons on it. These buttons can not be pressed without actual click and the control have no event or API for that. The control is something like the picture below which has multiple objects and buttons as a single control which controls inside the control can be changed dynamically according to some conditions but at a fixed place and this is why I think simulating a click that I said is the best way in my opinion:(The actual control is completely different that the picture below. It's only a sample)
I can click on the button by doing these steps:
Collecting all controls positions on my form
Moving the control in order to put the button exactly at the left top of the form
MyControl.Left = -43
MyControl.Top = -6
Moving form exactly to the center of the screen
Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width / 2 - 1, Screen.PrimaryScreen.WorkingArea.Height / 2 - 1)
Simulating a click action at the center of the screen
Moving back controls to their positions that I got in the first step
It can be done that way but it's not reliable and it might not be user friendly for my program customers.
I want to ask if there are any better method to do that like simulating a click event on a position on the form itself (so I don't have to move controls and do other steps)?
Of course I feel I must tell you that simulating a mouse click in order to programmatically click a button is not a very good idea. Many things can go wrong with this method (The form could move, making your mouse click on the wrong location; Form could be minimized, or another form could be on top of it, etc)
That said, it is possible, so take a look at this article that contains the code to simulate a mouse click.
http://www.developerfusion.com/code/276/simulating-mouse-events/
Once again, please consider doing this a different way. Iterate through the controls in the user control until you find the button you want and use button.performclick. Or you can call the function that the button.click event calls yourself, if it is public