MS Access: Update a Linked List Box - ms-access

I have a list box on an MS Access 2010 form that has its contents generated by a query. The list box lists new customer names; these names are the ones that are not listed in the Customers table in the DB.
The user can select a customer name on the list box and click a button to add that customer name to the Customers table.
Now, after the new customer is added to the Customers table, I want to refresh the table, i.e. I want to re-run the query that generates its contents. Is there a way to do this in VBA or by setting a property?
Thanks! :)

Listboxes, comboboxes, and forms/subforms have a Requery method that should refresh/requery/reload the underlying recordset.
Me.Requery 'Requery Form
Me.Listbox1.Requery 'Requery Listbox
Me.ComboBox1.Requery 'Requery ComboBox
Me.SubformControlName.Form.Requery 'Requery a subform
Choose the correct one above and change it to match the name of your control. I think you should put it at the end of your code on your button_click() procedure. In some scenarios you will place this code on a control's AfterUpdate event.

Related

How to create dependent form in MS Access based on Drop Down List

I want help in creating a pickup list in which there is a list of choices you pick and corresponding to the choice you choose the secondary form loads with its own listed fields.
EG. I have created 3 tables (Brand, Toyota, BMW), and each table has its own set of fields in them.
I want to Open Main Form(Brand) and create a drop-down list that shows Toyota and BMW). when I choose Toyota it should open the Toyota form as a subform inside the Brand Form and the same goes for when you choose BMW. I am new to access and would really appreciate anyone's valuable input.
I also reccomend "normalizing" to a single table with a "makeId" column and a "make" table. But it is possible to do what you are asking in Access if both the "Toyota" table and the "BMW" table have the same columns:
Create a datasheet form with the wizard based on either table.
Create a blank form with a combo box and subform control.
Set the source of the combo box to your "Brand" table.
Set the source of the subform to your datasheet form.
Change the recordsource of the subform on the combobox change event:
Private Sub brandBox_Change()
subform.form.RecordSource = "SELECT * FROM " & brandBox.Value
subform.Requery
End sub
I don't recommend it but is possible.

MS Access get number of sub rows in datasheet

I have a little problem here. I've a database with one table for Users and one for changes in progress for these users. They are in a 1:n relationship (one user can have many changes but one change only affects one user).
I output my users in datasheet view and have the changes in by standard collapsed subrows of this datasheet. The user shall be able to order the users by the number of ongoing changes matching the filters in this sub-form. Therefore i have to get the number of rows in this form.
in the subform i have a field called "Anzahl" (german for count) representing the number of elements currently shown in the sub-form and i have a field called SubFormAnzahl in the parent datasheet.
Now i try to access this field via
=[Changes_Subfrom].[Form].[Anzahl]
and i am getting a #Name? error.
Why does this happen and how can i prevent it?
With main form set as datasheet, it can't see subform textbox until subdatasheet is expanded, then the calc shows. If you want to keep main form as datasheet, options are:
set main form SubdatasheetExpanded property to yes.
DCount() domain aggregate function on main form - expression in query used as RecordSource or in textbox and must use same filter criteria applied to subform
DCount("*", "Changes", "UserID=" & [ID])
Otherwise, works with main form in Single view.

Updating Unbound combo box value lists

I have a database that allows an end user to search all available records in a table based on the criteria they have entered. I have a form with three command buttons (search, clear, and close), six unbound text or combo boxes, and a query. When the user enters data into the text or combo boxes they will click the search button and the query will use the users data to search the table for the results. All of this works great. My problem is…. The combo boxes are value lists. When I add new values to the list, all bound fields update automatically, but the unbound do not. Is there a way for me to automatically update those unbound fields when I update the bound ones too? My code for the search button is below if anyone has any pointers or thinks something needs changed.
The record source for the bound comboboxes is empty but has a control source from the table (manufacturer combo's control source is the manufacturer field of the table and the main form is bound to the table). The Unbound combo box has a value list record source and the form is unbound. If I bind the form to the table and the control source of the combo to the correct field of the table When I select a manufacturer as my search criteria it changes the records to that manufacturer instead of just finding all the records that match the criteria.
If DCount("*", "User Customer Owned Parts Query") = 0 Then
MsgBox "No Records Found"
Else
Me.User_Customer_Owned_Parts_Query_Subform.Requery
End If

Stop Subform Requery with Multiple Users in Access 2010

I have a very simple form with a combo box that is populated by a query. A user selects the class for which they want to enter data from the combo box and the records (passing the selection from the combo box to another query) for that class are loaded into a subform.
However, when multiple users are accessing the database and another teacher selects another class from the dropdown and starts entering data, the subform for the first teacher requeries and brings up the class selected by the other teacher.
How do I avoid this?
I have split the database into frontend and backend.
It would seem that the combobox for selecting the class is bound to a field in a table. That is why it is updating for one user when another user makes a selection.
You should make this combobox unbound (=clear the ControlSource property).
It is not clear to me if you are already doing this, but the correct way of filtering by a field (class in your case) is to set LinkMasterFields (of the subform control) to the name of your combox control and LinkChildFields to the class field in the the underlying recordset of the the subform.

Filter Access Combo Boxes

I have an access database with a form that contains two combo boxes. One combo box filters its options based on the selection of the first combo box. This works perfectly but - I have a command button that changes the record source of the form. I only know how to populate the combo boxes based on one table though. So when the form changes record sources the combo boxes are still filled with options from the first record source. How can I create a query that populates the combo box options not on one table in general but based on whatever the record source of the form is at the time?
In the same command button handler that changes the RecordSource, assign a new RowSource to each combo box. Better yet, do this in a separate sub that's called by the button handler. Your code will have to know, or be able to figure out, what the new RowSource should be to correspond to the new RecordSource.
Edit in reply to comments
The RowSource doesn't have to be a QueryDef object, it can just be an SQL statement:
Dim sSQL As String
sSQL = "select whatever from wherever"
comboBox.RowSource = sSQL
I can't see the comments at the same time I'm editing, but I didn't understand what you were asking in the second.... On a second, separate, look at the comments, I think you're asking it you can set the RowSource to the form's RecordSource property. This strikes me as a bad idea--you've probably got many more columns in the RecordSource than you'll want to deal with in the RowSource, and a basic principle of query construction is to only request the columns you want.