I have been using multiple forms that are exactly the same except they have different filtering e.g. frmChecklists-Group1; frmChecklists-Group2.
I realised I can just have frmChecklists, and use control buttons on a "switchboard form", such as 'Group 1', 'Group 2' etc. which open the form and apply the relevant query.
HOWEVER, I have on each form an unbound combo box that lists the members of the group, and has an 'after update go to matching record' macro.
What I need to happen: I click "Group 1" command button; frmChecklists opens with qryGroup1 applied; and my combo box is also filtered by qryGroup1. But I can't work out how to attach the query to the combo box on opening.
Related
I have three combo box controls(MFG, Code, and GrpID) in my VBA access form. Once the user selects an option from the first combo box (MFG), rest of combo boxes give me available options. But I need to do some validation i.e. what if the user decided to change the value of first combo box? The values of rest combo box should be cleared. All I need to do is once the first combo box is changed the second and third combo box need to be cleared out or at least set to focus on them so that users will realize that they can't use old values as first value is cleared in the first combo box. I added a code block 'AfterUpdate for first combo box as shown below:
Private Sub MFG_AfterUpdate()
Code.Value = " "
GrpID.Value = 0
End Sub
The problem after writing above code is: they don't get empty until they(Code and GrpID) get clicked. In other words, I need to click them to empty them every time I change the value of MFG. Can anyone direct me how do I clear them or at least focus them?
Set the combo to null to wipe any displayed value in them;
Me.Code = Null
Me.GrpID = Null
This assumes your combo controls are called the same as your field names.
Edit for clarity: Including the Me. makes sure your are changing the form control values. If your field names are the same as the controls then Access will change the underlying field values, and as you have discovered on your form these aren't reflected until you click in that fields bound control.
I have a form with two dependent cascading combo boxes with a textbox. What I want it to do is after I select the 2nd combo boxes (cboxHDD), the txtDescription would update or requery to the selection of cboxHDD. I found some examples online but I can't seem to get it to work update/requery.
The code to txtDescription:
With Me
.txtDescription.Value = cboxHDD.Column(3)
End With
The database is also provided in the following link:
Computer-HDD Database
Have you tried putting txtDescription.Value = cboxHDD.Column(3) in the "After Update" event of cboxHDD?
I have two tables named "REPORTS" and "REPORT_NAMES". In REPORTS there are 2 columns "REPORT_NAME" and "DATE". In REPORT_NAMES there is only "REPORT_NAME" column. I created a combo box and a button in a form. All I want to do is when I choose a report from the combo box and hit the "RUN" button, "Query1" is to be run. "Query1" is like below;
SELECT * FROM REPORTS WHERE (((REPORTS.REPORT_NAME) = [Forms]![Form1]![REPORT_NAME_Label]));
But when I choose a report from the combo box and hit the run button query runs but gives a blank datasheet.
It should be [Forms]![Form1]![REPORT_NAME] which is the combo box instead of [Forms]![Form1]![REPORT_NAME_Label] which is the label.
I have a combo box on a form that is linked to a SharePoint field, the combo box populates correctly however I am having difficulty trying to add VBA code to select all of the options or to unselect all options.
With a standard combo box you can use:
cmbBox1.value = ""
and that will reset the field. The same thing can be done with a list box that has multi-select enabled however this tosses an error, "This control is read-only and cannot be modified", with the combo box that has multi-select because of the lookup.
I have done some searching however no one seems to have a real answer other than to use a listbox instead and that isn't a solution here.
Has anyone worked with one of these fields and know how to select all of the options using VBA?
Here is a link describing this type of field but it does not discuss how to interact with it using VBA - http://office.microsoft.com/en-us/access-help/use-a-list-that-stores-multiple-values-HA010031117.aspx.
UPDATE:
There has been some confusion about the type of field I was describing so I have added some screen captures to show the difference between a combo box that allows multiselect, a list box that allows multiple options and a combo box with the option added.
First the field I was describing:
Second the list box:
Lastly the combobox:
These images visualize the issue that was described. As you can see there are multiple check boxes that need to be selected or unselected. Normally I would not create a field like this but as described above this is how Access interprets a combobox from SharePoint that allows for multiple selections.
After a ton of searching and trial and error I figured it out.
To unselect all of the check boxes it is
cmbBox1.Value = Array()
So with this information I figured that to select items they have to be in an array. Creating an array with all of the items that are in the combo box and then setting the combo box equal to the array will select all of the items.
I used a basic loop to set each element of the array
Dim SelVals(), i
ReDim SelVals(0 to cmbBox1.ListCount - 1)
For i = 0 to cmbBox1.ListCount - 1
SelVals(i) = cmbBox1.Column(1,i)
Next i
cmbBox1.Value = SelVals
Obviously then you aren't limited to only using the entire contents - you could assign any array and those would be the values selected.
http://msdn.microsoft.com/en-us/library/office/aa140084(v=office.10).aspx
I beleive this covers what you are asking
I have a form that needs to use two combo boxes but the values in the second combo should come from two different tables based on the first combo selection. If I select option A in combo_1 I want to list all the agency names from tblRefAgency in combo_2. If I select option B in combo_1 I want to list all of the carriers from tblrefCarrier in combo_2. I can add VB code to hide/show two different combo boxes and then overlap them, but I feel I should be able to do this in a query. Thoughts?
As long as you are dealing with a single form, you can easily set the row source of the second combo in the After Update event of the first combo.
If Me.Combo1=1 Then
Me.combo2.RowSource = "SELECT ID, Description FROM tblRefAgency
End If
If the 2nd combo is bound to a field, you will also have to set the combo in the current event to ensure that data is displayed properly.