I have a form, frmResults, which contains a subform control, frmResultsSub.
frmResultsSub is a subform control which contains a query instead of a form. In other words, its SourceObject property is set to the query, "Query.qrySearch"
Is there any way I can reference the fields of this query to e.g. to centre text or change field width?
I've tried these statements in the Open Event for frmResults, but neither was successful:
Me!frmResultsSub.fldA.Width = 600
Me.frmResultsSub.fldA.Width = 600
Reference the fldA field in the query the same as you would if it were the name of a textbox on a form contained in that frmResultsSub subform control.
Put this in On Load and verify it shows you the field name instead of triggering an error ...
MsgBox Me!frmResultsSub!fldA.name
Once you have that working correctly, you can work with the column's properties. During On Load, adjust its ColumnWidth property to change its width ...
Me!frmResultsSub!fldA.ColumnWidth = 600
That should allow you to set the width. But you also mentioned text alignment, and I don't see how to do that for a query column unless you create an actual form based on the query.
I don't think you can adjust column width on a query using VBA. You can however solve your problem using one of those methods:
create a form (AutoForm is ok) and make its default view as Datasheet. then use that form as the source of your subform control. that will be visually identical to your current solution.
use a listBox instead of a subform. It's quite versatile and you can easily set the listbox rowSource to any SQL statement. You will have to handle sync with main form data but it is very simple.
Try this: Me.frmResultsSub.Form.fldA.Width = 600
Related
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.
So I've got form which has a subform which binds to some textbox on the form. Now within the subform how can I get access to the value in the "child field"?
Here is a good manual about referencing.
Okay, I found a solution to my problem: the textbox on the form was some content of the currently selected row of a table. Now I added an event to this form for changes of the row-selection (Form_Current) which calls a method which manually sets the textbox value directly via a column of the selected table-row like this:
[Forms]![MainForm]![SubForm].[Form]![SubSubForm].[Form].SomeTextBox.SetFocus
[Forms]![MainForm]![SubForm].[Form]![SubSubForm].[Form].SomeTextBox = [Forms]![MainForm]![SubForm].[Form]![SubSubForm].[Form]![SubSubFormTable].[Form]![NeededColumn]
When you link the subform inside Form the filter will work automatically just add the field belong to the child field(ChiledTable). if this not what you mean provide sample of DB.
I am currently using multiselect comboboxes to specify filters for a query (that will go on to generate a report).
I have it all working fine, apart from the fact I would like to specify default values to each of these comboboxes when the form is loaded.
It seems like using the builtin default box in the property panel doesn't accept multiple values (or rather I don't know how to give it multiple values)
I have tried selecting the values I want at runtime using the Selected property of the control:
For i = 0 To Me.MyComboBox.ListCount - 1
Me.MyComboBox.Selected(i) = True
Debug.Print Me.MyComboBox.Selected(i) 'Returns false
Next i
But unfortunately that doesn't work. It doesn't give an error or anything, but setting it just doesn't seem to change the value.
Does anyone have any idea on how to achieve this? I would essentially like to go on to have an "All" button next to each combobox that selects all the values in the combobox, so preferably a VBA approach to the problem would benefit me the most.
Any help is much appreciated
Add the following before setting the Selected property:
MyCombobox.SetFocus
MyCombobox.ListIndex = 0
I have a database created in access 2000. A form with a subform (datasheet - defaultview) in it. I have added a label at end of the coloumns in subform and given hyperlink to open the object present in database itself. But when the form open nothing is visible after the coloumn ? I got four coloumns and had hide two columns via onload event of subform. the code is below
Me.SubGroupname.ColumnHidden = True
Me.GroupName.ColumnHidden = True
Me.BNFno.ColumnHidden = False
Me.BNFno.ColumnWidth = -2
Me.SubGroupName1.ColumnWidth = -2
How can I make it visible so that it will appear as a link at each row ?
Please help me.
If I understand you properly, you cannot use Datasheet view to display a control at the end of a row. Switch to Continuous Forms view, it will give you more control, but you will have to work a little harder to get a nice layout.
Alternatively, add a click event to one of the existing columns.
can someone give me an example of what a calculated control is in ms-access?
Say you add a text box to a form, normally it binds back to a specific field in a table, and its contents reflect the contents of that field. A calculated control does not refer to a specific field in a table, rather it displays the calculation done on one or multiple fields in the database. Sometimes, it may not use any fields.
Example of control source value from a calculated control
=[YearlySalary]/52
Presuming that there is a field called yearly salary in the table the form is based on.
A control that simply displays this field would have the following in the control source
YearlySalary
Note the control source for a calculated control starts with an =
you mean this?
Setting the Control Source of a control, generally a textbox, to a calculation creates a calculated control:
=1 * 2
=[TheDate] - 1
=[Stock] * [UnitPrice]
=DlookUp("TheField","TheTable","FieldX=1")
Different cases:
Text box control: here you may be using a trim("text") function to remove spaces and clean up the data--that process requires some calculation
List box control: a calculation may be involved in the query that comprises it's row source. The calculation could be the combination of some kind of cyclic function on a numeric field value which then dramatically changes the order of the data if so directed.
Command Button: a variable could change with the number of presses which in turn changes the command mode of the button. Could change the color of the button, or could hide the button after a certain number of clicks, or could change the column of the listbox that is sorted in a query--each click advances the sort to the adjacent column to the right.