Sorry in advance for the long description, but it seemed like the prudent course of action.
I am having a problem getting a combo box to correctly populate a text field in a subform.
Based on surfing the web and some helpful guidance on adding VBA to forms earlier this week here is what I tried.
I have created a table tblPgo showing several probabilities of a project proceeding and a corresponding descriptions.
I have a second table tblDetails containing information about the items we are selling.
These two tables interact in a subform tblDetals subform.
I added a combo box cmbPgoValue to the subform. The combo box gets its data from tblPgo
Control Source is Pgo
Row Source is SELECT [tblPgo].[PgoID], [tblPgo].[Pgo], [tblPgo].[PgoDescription] FROM tblPgo ORDER BY [Pgo];
The Row Source syntax was created by the combo box wizard.
In the subform, I created an unbound text box called Pgo Description to receive the PgoDecription text corresponding to the selected Pgo value from the combo box.
cmbPgoValue has the following After Update Event code
Private Sub cmbPgoValue_AfterUpdate()
Me.PgoDescription = Me.cmbPgoValue.Column(2)
End Sub
When I use the combo box to select a Pgo value, the correct Pgo Description populates the current record and the record below it. When I try completing the incorrectly populated record, I get an error about duplicating indexes, etc.
I've tried bounding the text box, but it does not seem to help.
Thanks in advance.
That is to be expected with UNBOUND textbox. There is only the one Description textbox so all records will show the same info. Should not be duplicating this info into tblDetails. Instead of VBA, just have expression in textbox ControlSource:
=cmbPgoValue.Column(2)
Related
I have form which contains a few combo boxes and some text boxes. There is another combo box (the row source is from another table) which needs to be filtered by the values the user entered in the previous combo boxes and text boxes but even if you entered the values you get the "Enter Parameter Value" message for each one. I used the expression builder for every criterion so its unlikely that there are any typos. What can cause this message to appear?
Code for the combo box's row source:
SELECT Profiles.profile
FROM Profiles
WHERE (((Profiles.Type)=[Forms]![AddItem]![typeComboBox]) AND
((Profiles.WindowOrDoor)=[Forms]![AddItem]![windowDoorComboBox]) AND
((Profiles.MaximumWidthPerWing)>[Forms]![AddItem]![widthUserInput]) AND
((Profiles.MaximumHeightPerWing)>[Forms]![AddItem]![heightUserInput]))
The SQL statement is in the RowSource, not a query object? If the controls are all on the same form, no need for the full form path reference. Works for me. Try:
SELECT profile
FROM Profiles
WHERE [Type] = [typeComboBox] AND
WindowOrDoor = [windowDoorComboBox] AND
MaximumWidthPerWing > [widthUserInput] AND
MaximumHeightPerWing > [heightUserInput]
I think Type is a reserved word, hence the [ ].
If it still prompts for input then Access can't find those names.
You also need code to requery the combobox. Put it in the form Current event as well as the combobox GotFocus event.
Be aware, cascading combobox doesn't play nice with continuous or datasheet form.
I have a Form A (Main form) with combo box taking values from a account master table. Whichever value a user will select from combo box is displayed on the same form in 2 text boxes. Now on pressing a button (On Form A) a query A runs after taking the values in 2 text boxes as inputs.
The results are displayed correctly in a separate tab created automatically in datasheet view.
However I want to display the results on a sub form on the Main form A. I have bound this sub form with the Query A and have placed this sub form on form A.
But still the query results are getting displayed in a separate tab and not on the sub form which seems to do nothing.
Please help.
If the results of the query that you are using as the Source Object for your subform are using the values of the comboboxes as query criteria, you may need to call SubformName.Requery after changing the combobox values.
If instead you are modifying the SQL behind your query rather than using criteria, I have found that you need to issue the following in order for the results to update:
SubformName.SourceObject = Subform.SourceObject
In my experience, when the SQL behind a query that is used as the Source Object for a subform is modified, the data displayed by the subform is not updated following a call to .Requery, but only after the SourceObject property is 'refreshed' using the method shown above.
Here is what I am trying to do:
I have a purchase order form for clothing inventory, with PO Lines as a sub form.
In the subform, I have a combobox called "Garments" (which is generic, like T-shirt, Dress, Pants, etc.) The ID from this result is supposed to filter the details combobox (which holds values like Black/Small; Orange/Large, etc.). The details combobox's RowSource has the following as a criteria: [Forms]![PO DETAILS Subform - New]![cboGarments] which the combo box that I select first.
In the "parent" combobox, I have a macro AfterUpdate, Requery "Child" combobox.
The issue is that when I try to select details, a Parameter window pops up. I can manually input the Garment ID, which gives me the right subset of details. I need the "child" combobox to get the ID from the "Parent" combobox and filter the list that way.
This YouTube video gave excellent instructions, but I think my issue might be subform-related.
https://www.youtube.com/watch?v=I_wwlZofCgk
EDIT:
This issue had to do with which field in the table I was binding the "child" combo box to. I would unbind it, and the filtering worked fine. I bound it back, and the field would prompt for a parameter. I decided to create a combo box from scratch and set the option "Store that value in this field" to the field I needed to populate in the table, then adjusted all the filters/queries. Works like a charm now. I still have no idea what went wrong.
You can't address a subform directly like this, you must specify the "full path", see http://access.mvps.org/access/forms/frm0031.htm :
Forms!Mainform!Subform1.Form!ControlName
so in your case something like
Forms![PO Mainform]![PO DETAILS Subform - New].Form!cboGarments
Note: [PO DETAILS Subform - New] is the name of the subform control on the main form - usually that's the subform name, but not necessarily.
I'm trying to make a database for paperwork for a summer camp. Right now I have a form setup that has a combo box with the the children's name in the header. And I have three tabs separating the different papers they need to turn in (medical, permissions, etc). I have the combo box working, sort of. When I click on it I have it showing the list of names, but I don't seem to have it connected to the underlying table, so it could show the records. The records are all a mix of checkboxes (yes/no) and text boxes (for additional comments). Does the combo box need to have an After Update event, or would it be in another event? I've tried copying some code that I've found, but it hasn't seemed to work. Right now there should be some information that shows up that I've already entered directly into the table, but other fields I know are blank.
My goal is to be able to select a child from the combo box and pull up their records and edit information as needed. I'm a real beginner with coding, but I think it's something that would lead me to a solution here. I've been across a variety of forms today and nothing seems to have worked for me yet. I'm also just beginning to learn access so I'm only starting to know the kinds of questions to ask. Any help or suggestions would really be appreciated.
In an Access form, there are either bound or unbound controls. Bound means table fields are connected and unbound means there are no table field connection. The same can be said about bound and unbound forms where bound has a whole table connected to form and unbound does not. If you enter Design View, you will either see a field name in textbox or "Unbound" written in textbox. For checkboxes you cannot tell unless you enter its Property Sheet \ Data tab \ Control Source.
From your explanation, you seem to refer to a search box. This would be an unbound form as no data should be tied to it. Your header of Student's Name seems to be a bound textbox of student name. Search boxes have an AfterUpdate event built in either as a macro or VBA that searches a record that matches the selection of the drop down:
Macro:
Search Record
Object Type: Form
Object Name: YourFormName
Record: First
Where Condition: ="[ID] = " & Str(Nz([Screen].[ActiveControl],0))
VBA:
DoCmd.SearchForRecord acDataForm, "yourFormName", acFirst, "[ID] = " & Forms!YourFormNam!DropDownField
Please note you can create a search box simply by placing a new combo box on the form and following the Wizard all the way through. The outcome of this will be an AfterUpdate event macro as listed above. You must have canceled the wizard before finishing to have an unbound combo box with no functionality.
I did the following in MS Access: I made a form which had a combo box and a button. You select an option from there and click on the button and it is supposed to open a report. Now, I wrote a query selecting a few fields from a table and in the where clause, gave the condition as where name=str(combo1.value) and the report source was specified as this query. Now, when I select the value and click on the button, it opens a blank report. How can I make it load only those particular values?
I am not saving the combo box value anywhere. It said that it would remember the value for later use. Am I doing the right thing by not saving it? What should I do to make this work? Please help me!
Edit: The combo box is using values from a column 1 in a table X. I've not bound the value to any field and am using the "Remember the value for later use" option provided. The combo box is essentially a list of hotels and the report is a list of people staying at the selected hotel. When I put the ID of the field (as defined in the X), it works. But the thing is, it should refer to the names of the hotels and not the ID, which I am supposed to enter in a popup that asks for it. What do I do?
Edit 2: The query is as follows:
SELECT Table_1.Hotel_Name, Table_2.Name_of_Delegate, Table_2.Address, Table_2.City, Table_2.Center, Table_2.Spouse_Present, Table_2.No_of_Children, Table_2.No_of_Guests, Table_2.No_of_Rooms
FROM Table_1 INNER JOIN Table_2 ON Table_1.ID=Table_2.Hotel_of_Residence
WHERE Table_1.Hotel_Name=FormName.Combo7.Text;
When I click on the button (which opens the report), it asks for the name of the hotel in a popup box. How can I avoid this? What I am doing wrong?
You can use a WhereCondition with the DoCmd.OpenReport Method as a "dynamic WHERE clause" for your report's record source. Use something like this in the click event of the command button which opens your report.
DoCmd.OpenReport "YourReport", , , "[name]=" & Me.combo1
Remove the WHERE clause you added, where name=str(combo1.value), from the report's query.
I surrounded name with square brackets because name is a reserved word. See Problem names and reserved words in Access
Edit: In a comment, you said this about the combo box:
"Row Source is SELECT [Table_Name].[ID], [Table_Name].[Name] FROM [Table_Name];. Bound Column is 1 (which I assume shows the names I wish to be displayed in the combobox.)"
When you refer to the value of a combo box, that value is the value of the "Bound Column". So in your case, the bound column is 1, which means the combo value will be [Table_Name].[ID]. However, you want to open your report based on the [Name] column of the combo. So change the bound column of the combo from 1 to 2.
To open a report using the value of your combobox, in your report query you need to do the following:
SELECT fields
FROM table
WHERE YourValue = [Form]![FormName]![ComboBox Value]
You have to specify the name of the Form, plus the value so the report query knows the value. Hope this helps.