I have a form with several groups of controls and I want to be able to toggle enabled/disabled those groups individually with a Toggle Button control. When the form loads, I programmatically assign a UDF called ToggleGroup to each toggle button's AfterUpdate() event handler. I have tested this part of the code and know that it performs as intended.
I want the groups to start in a disabled state, so I want to trigger the AfterUpdate() handler for each toggle button after I assign the function. I know that I could achieve this in a few other ways (I could change the properties of the grouped controls in Design View or I could call ToggleGroup on them as part of the form's initialization), but for my own curiosity and interest, I want to know if the method I described is feasible.
'''GroupTags is a collection of all Tags associated with control groups
For Each iTag In GroupTags
CtrlName = "Toggle_" & iTag
Me(CtrlName).AfterUpdate = _
"=ToggleGroup( ...valid arguments... )"
'''Here: trigger the AfterUpdate event for this control based on CtrlName
Next iTag
Related
I have a Tab Control element containing 2 tabs: Tab1 and Tab2. Tab2 contains a ListBox element whose RowSource queries the data that gets submitted in Tab1.
Say the user opens this form containing these 2 tabs. They are originally on Tab1. in the Form_Load event for Tab2, it queries the data it needs to populate its ListBox. Now they switch tabs to Tab1. They enter some data and submit a new record to the corresponding table (the same table that the Tab2 ListBox uses as its RowSource). When the user switches back to Tab2, they don't see this newly added record.
What I have done so far is that when the user clicks anywhere in the ListBox, it calls Requery, and then the record will show up. This isn't enough as it's not intuitive for the user to have to click on the listbox to update its contents.
I have tried putting this Requery code in a Form_Load, Form_Activate, GotFocus, but nothing works. I know you can detect the TabControl clicks, but how can I access the forms and the elements that they contain?
Any ideas on how to requery this listbox whenever the tab gains control?
If you want to add code for a specific tab on a tabcontrol, the most convenient way to do that is to write code in the TabCtl_Change event. That occurs when the tab control is changed. E.g.:
Private Sub MyTabCtl_Change()
If MyTabCtl.Pages(MyTabCtl.Value).Name = "Tab2" Then 'The tab control just changed to your page
'Requery that list box
End If
End Sub
Note that, if you're not using a tab control at all, but a navigation control (which it does sound like, tab controls don't necessarily have subforms on them, and don't have Form_Load events, forms do)
You're most likely looking for the On Activate trigger.
Then, in the code just use Form.Requery or Form.Recalc depending on which you're actually looking to do.
Alternatively, you could use the same control the user is using to submit records to trigger a requery. Although, that would require a specific Form to be called into focus.
I have created a front and back-end database MS Access solution (I am limited to MS Access 2013) for my team, utilizing forms for data entry, lookup, and editing. It is working well, but every now and then a user will forget they are in "Filter by form", and enter data into the filter instead of the actual form. When they realize their mistake, they have to re-enter all of the data.
Is it possible to change the appearance of the form when you are in "Filter by Form"? For instance, change the background color, or add a text box notification so that it is very obvious to the user that they are in "Filter by Form"?
You could use the Me.FilterOn property to help determine whether the form filter (ie., Home→Advanced→Filter By Form ) is on.
You might need to play with it a bit but from my experiment, you could have something in the OnOpen event that checks the property and acts appropriately.
I believe the catch is that code won't execute when it's in Filter mode, so therefore, you'd have to make the default appearance the "Filter appearance" (perhaps add a Graphic or Textbox that says "Filter Mode"), and then if Me.FilterOn = False you can hide that label in the OnOpen event.
Also:
The Apply Filter button indicates the state of the Filter and FilterOn properties. The button remains disabled until there is a filter to apply. If an existing filter is currently applied, the Apply Filter button appears pressed in.
To apply a filter automatically when a form or report is opened, specify in the OnOpen event property setting of the form either a macro that uses the ApplyFilter action or an event procedure that uses the ApplyFilter method of the DoCmd object.
(Source)
More Information:
Office.com : Apply a filter to view select records (Form Filter)
expertsexchange : Determine if filter is applied
MSDN : Form.FilterOn Property (Access)
I have a main form (frmCustomer) bound to tblCustomers, and a tabbed subform with 2 pages, one bound to tblCustomerAddress and the other to tblContacts.
I don't want the user to be able to insert data in the tabbed form, until I have a valid CustomerID.
I tried (on current event of main form, before update)
If isNull(Me.CustomerID) then
Me.Page_Address.Enabled = False
end if
But it disables the tabbed form and keeps it disabled forever...
Thank you so much for any thoughts as I am clueless.
As well as the Current event, perhaps need to put code in another event, such as AfterUpdate of first control on main form that gets data input.
Then instead of If Then, simply
Me.Page_Address.Enabled = True
or
Me.Page_Address.Enabled = Not IsNull(Me.CustomerID)
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.
I have form that displays information on a project. Most of the fields on the form are bound to a Project table and display and update as bound fields do. However, I also have 10 checkboxes that come from a ProjectAudience table. Only if the box on the form is checked, is there is a matching record in the table. Therefor, I need to insert and delete records as these boxes are checked and unchecked.
I can do it at the checkbox level with the AfterUpdate event, but that would require 10 different events. I looking to do it at the Form level by deleting all records in the ProjectAudience table for that project and adding in the checked ones.
Basically, I'm looking for the opposite of the Form_Current event that will fire when either the record navigation button is fired or the form is closed. I'm trying to avoid either writing my own navigation buttons or adding a "SAVE" button to the form that the user must press. I want something automatic that will update this table when the user navigates away from the record.
Based on a comment below: Any combination of boxes from none to all can be checked not just a single box. Therefore, it is possible that I would wipe out all records and not insert any back... or add 10 records if every box was checked. (Also, I am using Microsoft Access 2003)
Have you considered adding these checkboxes to an Option Group and using events from that group?
EDIT re Comment, Alternative approach, do not use an option group, but add code to an event line for all relevant options.
You do not need code for 10 different events, you can set the event line for, say, On Click to the name of a function, let us say:
On Click : =TestMe()
Event Line http://ltd.remou.com/access/EventLine.png
You then need a function:
Function TestMe()
MsgBox "You clicked " & Screen.ActiveControl.Name
End Function
You can use the BeforeUpdate method. However, if only the checkboxes have been changed this event will not fire since the record to which the form is bound didn't change.
I would advise to link events to the checkboxes. Create a function UpdateCheckbox(CheckboxID as integer) that does what you want and put this in the 'OnClick' event from the ckeckboxes: =UpdateCheckbox(1). Change the 1 for the different checkboxes.