I am trying to populate a form controls default value based on the value of a combobox on that form. The combobox is called Title, and I want the control HIPAA to populate based on the value of HIPAA in my table tblTrainingEventTiles where the Title selected on the form matches the title in the table.
I was putting the following code into the default value of the control on the form:
=IIf(IsNull([Title]),0,DLookUp("HIPAA","tblTrainingEventTitles","[tblTrainingEventTitles].[Title]=[Title]"))
Access seems to ignore it however. It doesn't do anything and there are no error messages. I'm not sure if my problem is with my dlookup or with the fact that I'm trying to use this in the default value field. (or both?) Does anyone have any ideas?
Try this:
=Nz(DLookUp("HIPAA","tblTrainingEventTitles","[tblTrainingEventTitles].[Title]=[Title]"),0)
If your combobox's bound column is text you should use ' around it's content. And you should concatenate value of combobox to filter part of dlookup.
=IIf(nz([Title],"")="",0,DLookUp("HIPAA","tblTrainingEventTitles","[tblTrainingEventTitles].[Title]='" & [Title] & '"))
Related
I have a form in Access with a textbox and a combobox, and need to filter the combobox dropdown options using the value in the textbox. The textbox contains a Category for the choices.
I've done this using
SELECT Options.Choice
FROM Options
WHERE (((Options.Category)=[forms]![FormName]![Text10].Value));
Is there a way to refer to the value in Text10 without explicitly referring to FormName?
I'll need to duplicate this form within the same Access file and changing all combobox row sources for a new form is not feasible. I can't hard code the Category value for each combobox because there are many comboboxes per form, and the value in the textbox will be different on every form. Any help is appreciated.
You can refer to whatever form you're currently on in Access using Screen.ActiveForm. So in your case you'd have:
SELECT Options.Choice
FROM Options
WHERE (((Options.Category)=[Screen].[ActiveForm]![Text10].Value));
As long as the field name stays constant this should work.
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
I am using the djFilteringSelect control to show values in a dropdown as user type a value.
The lookup and typehead is working fine. The user type a letter and the dropdown allow the user to select a value which is then displayed in the dropdown field.
If the user now decide to remove the value first selected so that the combobox is empty and leave the field, then the first value in the list is now automatically filled in.
The consequence of this is that if the user have added a value there is no way to remove the value and leave the box emtpy.
I am using required=false for both the control and the dojo attribute but it does not seem to help. There are also a few other djFilteringSelect attributes I have tried like "Autocomplete" and "trim" but it does not work
Here is the code
<xe:djFilteringSelect id="test" type="select" store="jsondata" searchAttr="data" required="false" labelType="html" invalidMessage="Not valid">
<xe:this.dojoAttributes>
<xp:dojoAttribute name="required" value="false"></xp:dojoAttribute>
</xe:this.dojoAttributes>
</xe:djFilteringSelect>
Initally the field is not required, but if the user have entered a value it is required.
My question is if there a way to prevent the djFilteringSelect control to always populate the field if I have previously added a value
I found someone who solved this in another stack overflow topic, by creating an empty entry in my data store. but I could not get this to work
Dojo: Select of empty value for FilteringSelect while required=false
I do this quite a lot. Right now I don't have a working sample to show you (since I moved to bootstrap - and have to code the selects by manually adding select2 controls) but something like this should do it...
I add an "empty" value at the top of my select - and that seems to work no matter whether I am using a combobox, djCombobox or combobox with select2 from bootstrap. My markup typically looks like:
<xp:comboBox id="inputLocationSelector" value="#{User.catchListType}" disableClientSideValidation="true">
<xp:selectItem itemLabel="(none)" itemValue=""></xp:selectItem>
<xp:selectItems>
<xp:this.value><![CDATA[${Configuration.meta.listLocationTypeOptions}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
Then you could specify "(none)", "All" or " " for the "not-selected" value depending on your needs.
Validation is a different thing so just specifying "required=false" does not give you the "empty" value.
/John
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 would like to display a field's description on a form. How would I accomplish this? For example, table name is tblbureau, field name is Counsel with a description 'General Counsel for the Defense', form name is frmCounsel. I'd like to use a control (textbox?) that displays the full description instead of using the default label for the field name. Thanks.
If you have used the form wizards to create the form, any descriptive text is added to the StatusBarText propery. This is even true when you create a blank form and drag fields from the field list to the form. You can refer to this property for your message box, or just refer the user to the statusbar. You can also update the ControlTipText property with the StatusBarText property.
MsgBox Me.ATextBox.StatusBarText
Using the above will save coding to get the description:
Currentdb.TableDefs("atablename").Fields("afieldname").Properties("Description")
Note that the description property is not available for fields when you have not added a descrition, so the above would cause an error.