Mainform textbox referencing combo box in subform on Microsoft Access - ms-access

Quick question to do with Microsoft access. I've only been using it for about a week, so theres a lot i dont know.
I have a form with a sub form in it. In the sub form there is a combo box. When the user selects a value in the sub form combo box, i want the mainform's textbox to show what the user picked from the combo box.
I dont think it should be very hard to do, i just have no idea of what the code should be. Thank you in advance!

You can use the After Update event of the subform combo and refer to the main form as Me.Parent. Your code might look like this:
Me.Parent.txtTextBox = Me.cboCombo

Related

MS-Access 2007 - How to programatically access sub form columns data on click event

I have an unbound form that includes a subform.
The subform is unbound and gets populated when the user clicks on a push button on the main form.
I want to be able to grammatically handle the click even on the sub form and get the data in a specific column. How can I do that? The same thing one would do with VB.NET/C#.NET if you know what I mean.
When I use the properties tab of the subform, I get an expression builder. That does not get me into a sub/function/form or module VBA code editor.
Any help is appreciated.
Edit - Something that worked!
Thanks for the help I got from the answers below.
One way to refer to column in a selected row in a subform is by using this expression:
Me!ChildFormName.Form!ColumnNameInSubForm
EX:
ME!Sales.Form!SalesmanID
Additional Reference here...
A problem with this approach is that the available events On Enter and On Exit don't behave like "click" event does. One needs to focus out of the sub form (by clicking on another control) for either to be triggered!
Look again. The Properties' sheet has a tab, Events. Select any event and select "Event Procedure" from the dropdown and click the ellipsis - that opens the code editor.
Refer to sub-form control form main-form event handler (VBA Sub):
Me!Subform1.Form!ControlName
Me is self reference to the main-form, Subform1 is the control containing the sub-form, Form is a reference to the sub-form, and ControlName is a reference to the field on the sub-form. ! is a short way to refer to a control in a form's contrls collection.
A longer way to write the above would be: Me.contrls("Subform1").Form.Contrls("ControlName")
Refer to a main-form control form a sub-form event handler (VBA Sub):
Me.Parent!ControlName
Me is self reference to the sub-form, Parent is a reference to the main-form, and ControlName is a reference to the field on the main-form.
A longer way to write the above would be: Me.Parent.Contrls("ControlName")
Please see more on the topic in this link.

Setting focus on a sub form

I have two sub forms embedded in control (the one that looks like a set of folders allowing you to change from tab to tab.. Sorry I don't know the name in English)..
Both sub forms are embedded on one sheet, I would like that immediately after executing a routine, I wrote on one of the subforms, that the set focus then goes to the other sub form.
For some strange reason I can't get it to work. The sub form and field I'm trying to go to are frmObjectives03 and Effective_date.
I tried:
Forms!frmObjectives03!Effective_date.Form.SetFocus
but it doesn't work.
I would appreciate any insight.
Thank you,
The control you speak of is a Tab control.
Because frmOjective03 is opened as a subform, it is not part of the Forms collection. Instead you can use Forms!MainForm!frmObjectives03.Form!Effective_date.SetFocus from anywhere, or Me!frmObjectives03.Form!Effective_date.SetFocus from within the main form or Me.Parent.Form!frmObjectives03.Form!Effective_date.SetFocus from the sibling subform.
If these are not working for you, please check the name of the subform control in your main form (because it may be Child17 instead of frmOjective03). Open the main form in design view, click on the subform ONCE and look in the Properties->Other->name.

MS Access: Subform doesn't work, but the main form does

I have a form with a button that updates data in a table, form which works perfectly. However, when I add it as a subform on a tab paged form, it no longer does. Access prompts out asking for the [Forms]![MyForm]![textbox] variable, although it exists and is filled out. I'm guessing there's a different way to reference a subform.
Refer to the name of the form, the name of the subform control, the form property and the name of the control (reference MVPs, MS ). You have MS Access 2010, so you can use the query design window and intellisense to build the relevant string, it will work put something like:
[forms]![Gestiune]![SubformControlNameHere].Form![idInchirieri]
The expression [Forms]![MyForm]![textbox] probably appears within the query used as RowSource of a ComboBox or ListBox on the subform. This subform is now no longer Forms!MyForm but
Forms!MainForm!MySubformControl.Form
I don't know the correct names, adapt them accordingly.
Change the expression to something like
Forms!MainForm!MySubformControl.Form!textbox
Forms is the collection of the open forms. (invariable)
MainForm is the name of the form with the tab control. (adapt)
MySubformControl is the name of the control containing the subform. (adapt)
.Form designates the subform itself. (invariable)
Finally textbox is your TextBox. (should be ok, otherwise adapt)

Access 2010 - What Control Name do I use to Requery this Subform?

I am now learning MS Access and I have run into a problem. I have found similar questions but after trying them I still can't figure this out.
I have added a button on a form that updates a table behind a subform and I now need that subform to display the new data. Can anyone tell me what to use as the Control Name or if I'm even on the right track to get what I want?
My main form is "EnterEmployeeSales" and my subform is "RetailSalesSubform".
Here are some screen shots of what I'm trying to do:
EDIT: I figured it out. I was making it TOO COMPLICATED!
I kept trying to enter stuff like "Forms!Yadda!Yadda" but all I needed to enter was the subform control's name only into the Requery "Control Name" field on my screen shot above. Imagine that! Here is a screenshot on how to determine the subform control's name (for other loser noobs like me):
There are two parts to a subform, the subform control and the form contained. It is important to use the name of the subform control to requery, not the name of the form contained. So:
Forms!MyMainForm!MySubformControlName.Form.Requery
Or when writing code in the form module:
Me.MySubformControlName.Form.Requery
An advatage of using Me in the form module is that intellisense will give you the name of the subform control.
More information: http://access.mvps.org/access/forms/frm0031.htm
The macro is one way to do it. VBA can also do this. In your case in the "onclick" event you could put the code:
Docmd.Requery "ServiceSalesSubform"
It does the same thing but sometimes it is nice to have everyting in VBA code. When there is a mix of code and macros it can get confusing to tell what is happening and when.

MS Access linking combo box to form

I'm trying to link a field, which I have a drop down box in, to a form. I have a list of about 10 forms to pick from. I'm sure this is simple, but I'm just overlooking the obvious.
Simple example code for the opening from the EventName() event (change EventName based on what event you are using):
Private Sub Combo0_EventName()
If Combo0.Value = "Form1" Then
DoCmd.OpenForm "Form1", , , acFormAdd, , , stLinkCriteria
ElseIf Combo0.Value = "Form2" Then
DoCmd.OpenForm "Form2", , , acFormAdd, , , stLinkCriteria
End If
End Sub
Depending on what you are trying to do will determine the event to use, but running the open form command in that event based on the combo box value will get you where you need to go.
Let me understand this right, you have a form with a combo box. When the user selects an option from the combo box, one of 10 other forms open?
How about, in the On Change Of event of the combobox, open the second form?
To clarify:
You open up Access and are presented with a form that contains a combo box filled with some values. You select one of the values and want to bring up a different form and then fill that form out based on some criteria.
The sub routine Combo0_EventName() will take care of opening a form based on the field you select, just put the code in the Combo0_AfterUpdate() routine. To get to that right click on the combo box in design view and select Properties, then click in the "AfterUpdate" event to get [Event Procedure] to show up then click the ... button to get the VB editor.
If you want to fill out the form you open up automatically the method depends on what you are trying to do. You probably want to have another combo box on the first form or on the other forms you are opening that allows you to select your query parameters. Lets say you are opening a form that displays someone's address. You would want a combo box on that form to select from the names in your table and when you select a name it would update a textbox with the address information. Or you could put your query parameter selection on the main form and tie that data to all of the forms so you can go through the forms with the same entry in the table, useful for something like order entry.
If that sounds like what you are trying to do we can move forward down that path, or if it is not please clarify. Can you describe an example of what you are doing? That would be helpful.
I'm sure we can get you going with this.
Im trying to make local tax forms. We do several different local forms and just want the person perparing the return to be able to put in the basic information in a form, which will then automatically pop up which form they are to use, completely filled in. This way all they have to do is enter the basic info in a standard sheet and the local form automatically gets completed. I have made it so when i person picks the municipality from the drop down box it automatically list the form name it needs to go in. But i want it to be simpler than that for them. NE Suggestions?
That makes sense, each form probably has different tax codes, addresses, etc. on it.
I'll see what I can do over the next couple days and set you up with something to get you going.