Switch between subforms in Navigation Form - ms-access

I have been searching for hours on what seems like an easy question, so alas, I will ask here. Working in MS Access with a navigation form, attempting to switch between navigation buttons/tabs in VBA to search for assets I wish to add to the project.
I have a Navigation Form with a number of navigation buttons to include btnUpdateProject and (hidden) btnSearch. btnUpdateProject has a subform named ProjectIndex with a btnSearchForAsset button (so I can search for assets I may wish to add to the project). I have VBA code:
Private Sub btnSearchForAsset_Click()
Me.Parent!btnSearch.Visible = True
Me.Parent!btnSearch.SetFocus
End Sub
The btnSearch becomes visible, per first command; however, the focus remains on btnUpdateProject. How do I get the btnSearchForAsset to be the focus? Much thanks for any help!

First of all you have to navigate to the form page and than setfocus on button.
Me.TabCtl1.Pages(1).SetFocus ; This will set focus on the Navigation page
Me.Parent!btnSearch.Visible = True
Me.Parent!btnSearch.SetFocus

Related

Paste a value in a textbox on the second tab of a navigation form access vba

I'm quite new to VBA and I've been looking around but cannot seem to find a solution to my problem.
I have made a navigation form (frmNavigation) with 3 buttons, each referring to a different form, let's call them frm1, frm2 and frm3. In the navigationform the control buttons to switch between tabs are all named differently (btn1, btn2, btn3), but the subform that shows either frm1, frm2, or frm3 has the same name: “NavigationSubform” (this shows a different form depending on which tab is clicked on, based on the 'navagation target name' referring to frm1, frm2 and frm3).
When I want to refer to a textbox (txtBox1) on form 1 (first tab) and insert a value i can do this by:
Forms!frmNavigation!NavigationSubform.Form!txtBox1.Value = "insert awesome text"
But how would I refer to txtbox10 on the second tab (frm2)? Just using the following does not work:
Forms!frmNavigation!NavigationSubform.Form!txtBox10.Value
You then get the error 2465 (can't find the field).
I’ve been trying many different things, but can’t seem to get it right. So how do I refer to a textbox on a different tab than the first one?
Help us much appreciated!
Only one subform can be loaded at once. So you've just got to break this process into two steps.
Store the value from txtBox1 somewhere outside of the NavigationSubforms (a textbox on the parent form with visible = no, a global variable or a table works).
In frm2's On Load event, set txtbox10 to be the value you stored.
Just note, that you will need to add conditions in the On Load event if you want to avoid that textbox being set to an empty string or a wrong value if you have a setup where your filter is changing.

Toggling the Caption on a continuous Form

On a continuous form I am attempting to toggle the caption of a toggle button to match the button’s state. In this case when the record/state is True, I would like the button to read “Current” and if the record is False have the button read “Obsolete”.
The script below works in switching between the two desired values but is switches all of the visible buttons and not for the individual records. I am not sure how to tie the individual records to the individual togglebutton's caption.
Private Sub Toggle5_Click()
If Me.Toggle5.Value = True Then
Me.Toggle5.Caption = "Current"
Else:
Me.Toggle5.Caption = "Obsolete"
End If
End Sub
I am using MS- Access 2013, I expect this question has been answer before, I have not found a working solution.
As Gustav wrote, you cannot do this directly. All static properties of controls in a continuous form always apply to all instances of that control.
Possible workaround:
Use a textbox (disabled & locked, perhaps with special effect = Raised) to show the text, with a control source like this:
= IIf([Status]=True, "Current", "Obsolete")
Put a transparent button on top of it, for easy clickability (it won't show a Click animation though).
Use Conditional formatting to set the background color of the textbox.
You can't.
An unbound control in a continuous form carries the same values and properties on all records.

Populate textboxes with value from listbox selection on child form

I realise this question has been asked before and I have tried numerous suggestions, but I guess I am just too much of a novice when it comes to VBA coding.
Here is my scenario:
I have an Access 2007 "Application" with a few forms. On the main form, I have 2 text boxes. For simplicity let's call them textbox1 and textbox2.
textbox1 is used to enter a style code. a button on the main form then opens another in modal/dialog mode and runs a query with the style code as the where clasue. the modal popup gives me a list box which is populated from the database based on the query that was passed. I then need to select one of the products in the list and upon closing the popup, populate textbox2 with the brand (column2 in the list from the popup) number.
Please remember that I am a novice. Any help would be greatly appreciated.
I would put a button on the second form, and in the _Click() function, put something like this
If ListBox1.ListIndex = -1 Then
MsgBox "Nothing Selected!"
Exit Sub
End If
UserForm1.TextBox1.Text = ListBox1.List(ListBox1.ListIndex)
Unload Me
Where ListBox1 is the list box containing the content you need the user to select from, where UserForm1 is the name of the calling form, and TextBox1 is the name.
Explanation
The ListIndex property of the list box returns the index of the selected list item. If nothing is selected, it returns a -1.
To reference an item on one from from another, you reference the form, the object and the property.
In The example I gave, the form is UserForm1, the object is TextBox1 and the Property is Text. While typing, intellisense should auto complete the object and properties once you type the period.

use caption of pressed button from main form in query of other form

My problem is:
Main form has 9 command buttons and continuous subform. Click on some button open other form with text box for entering quantity and two command buttons. When click on the first button I want to use caption of pressed button from main form for query. How to get that button caption?
Thanks.
You have just clicked the button, you know the name of the control, so I do not quite see the problem, other than that it all sounds like quite a bad idea.
Private Sub cmdClickMe_Click()
Debug.Print Me.cmdClickMe.Caption
Debug.Print Screen.ActiveControl.Caption
End Sub

MS Access = referencing a control that is within a sub form

So I have a form, with a subform control that acts as a navigation scheme for my Main Form. Within the sub form, there is a sub form2 that actually contains the controls for data entry.
So the Main Form is almost just like a design shell around the sub2 within sub1 structure. So in subform1 there is 10 clickable buttons that open 10 different forms in the subform2 window. The subform2 contains the controls.....so here is my issue/question:
So if I have a click event on the subform2 where i am trying to open the next form (subform2 form) within the subform1 child control, which is within the Main Form, what is the vb syntax for handling this?
I am not sure if i am asking this correctly.
I tried:
Forms!SubForm1.MyChild.sourceobject = "NextSubForm2"
but this only works if the Main Form is not open....like if I only had the SubForm1 open.
One more thing, this is code behind the form of the SubForm2 (2 being the sub within the sub within the form).
The main form from a subform's point of view is:
Me.Parent
You can build on this:
Me.Parent.Subform1ControlName.Form.AControl
See also: http://www.mvps.org/access/forms/frm0031.htm
So:
Me.Parent.Subform1ControlName.SourceObject = "SomeForm"