Trying to open another form in Access based on a field in the current form - sql

I have a form that's just a list of descriptions (desc.) of other forms. Right now, when you click on a desc., the appropriate form opens; but it's done through a series of if statements in a macro. This isn't going to scale well once more forms are created.
I have a table that has the desc. and the form that is supposed to go to. I want to write a script that uses this table to open the new form based on the desc. clicked, but not using if statements. The end goal is to be able to just add a row to the table for any future forms that are created without making changes to the script or form. Is there a way to do this?

Use a combo box whose row source is a query which selects the form description and name fields from your table.
The combo will have 2 columns. You can set the width of the form name column to zero if you want to present only the form descriptions. If you make the form name column the combo's bound column, you can reference it conveniently in a DoCmd.OpenForm statement. For example, you could have a command button whose click event opens the form which is currently selected in the combo ...
DoCmd.OpenForm Me.YourComboName.Value

Related

Update table column line by line based on yes/no values from combo box

I am very new to Access and VBA but what i'm trying to do is simple:
I have a table which i want to show in a form, i have put said table in a subform box.
I want to have a column in which i want to update the status based on options from the combo box (yes/ no/ maybe).
So as shown in the picture: i want to select a line in the subform and update the column status by selecting an option in the combo box.
You can modify the selected record in the subform in the AfterUpdate event of the combo box.
Private Sub cboStatus_AfterUpdate()
subForm1.Form!Status = cboStatus
End Sub
This assumes that your combo box control is named cboStatus, your subform is named subForm1, and the field you want to update is named Status. It also assumes you aren't using numerical ID's as foreign keys for your values.
You will only be able to update one row at a time.
Beyond the scope of your question....
There are numerous other ways to develop an interface to edit the row. One way is to modify the field Lookup properties in the table. You can change the Display Control to a Combo Box, set the Row Source type to Value List, and then set the Row Source to a list of possible values separated by semicolon.
Now whenever you open that table in a datasheet view (like the example on your subform) a dropdown will appear in that column. A user can edit directly in that view without requiring a separate combo box control.

Prevent all Access Form ListBoxes from updating

I have a form that gets populated with rows of data from a database. I want to add a listbox to each row for the user to select a letter grade. When I run the form all the data looks correct, but if I update a single listbox all the listboxes in the form update to the same value. It seems like the listboxes aren't independent of each other.
An unbound control will always display the same on all records.
For individual display, you must bind it to a field of the record - or redesign your form in some way.

How to get event when moving recordsets Access form?

I have an Access form which uses SQL to populate dropdowns. This SQL is using a value in the form for a combo box cb_Priority, such as:
SELECT ProjectPriorities.ProjectPriority FROM ProjectPriorities WHERE (((ProjectPriorities.[mType])=[Forms]![testQuery]![mType].value));
In other words, I am using the current recordset to populate a dropdown on the form.
I would like to call the following when a user moves between records (ie which one is currently displayed in the form).
Form_testQuery.cb_Priority.Requery
This repopulates the form dropdown correctly.
However, I cannot find the event for what I would imagine to be something like
Form_RecordsetChange()
Form_RecordsMove()
How I trigger this .Requery method to allow it to run each time the userform updates to a different record?
The event you are looking for is: Form_Current.

how to populate textbox with the database value based on combobox change in access

I am new to Access and vb and i have failed to get the result what i am thinking to get ,hope i will resolve with your help guys
->my access database contains one table with following fields
firstname lastname middlename phone
I have two combo boxes and two textboxes
combobox- it populates firstname and based on this selection the other combo box has to fill with last name which i did successfully with the help of Me.Combo2.Requery
but i dont know how to fill middle and phone in textboxes
here i am failing in mapping recordset and connectionstring with my table and getting result to textbox value can any one help on this
You still have not said where the connection string comes from or why. The big advantage of Access is that it is fast and easy, for the most part, you do not need connection strings.
First, select your table, then choose create form. This will create a single form bound to the table. You could have created a query first and chosen that instead.
That is it. You have a form that displays your data. The key to this is the property sheet for the form, which you can find by switching to design view and double-clicking the small square at the top left of the form just under the form name. The property sheet will show the name of the table or query on the Data tab under the Record Source propery. You can, of course, set this property manually.
You can now add a combobox to select records, but you do not have to, there are navigation buttons at the bottom of the form.
To add a combobox that selects records on your form, you must have first bound a recordset to your form using the steps above. Next, ensure that the wizard is selected for the toolbox. Unless you have unselected it, it will be selected. Now choose combobox from the toolbox, it will open the wizard.
Choose find a record on my form and press next to choose the relevant ID field / column and any other fields that you need. When the wizard completes, in MS Access 2010 (and probably in 2007) it will add an embedded macro that finds your record and in earlier versions it will add code. Other properties set by the wizard will look something like this:
Row Source : SELECT ID, Firstname, Lastname FROM Table1
Column Count : 3
Column Widths : 0cm;2.54cm;2.54cm
Your table should have an ID, add one before you start, if it does not. The wizard will not add a Control Source when this option is selected because it is not needed, in fact, it would be a disaster to add a Control Source to a combo that finds records. Once again, you can do this manually. The code to find a record might look something like:
Private Sub MyCombo_AfterUpdate()
With Me.Recordset
.FindFirst "ID=" & Me.MyCombo
End With
End Sub
This works because the bound column of the combo is set to 1, the first field of the select statement, which is ID.
The combo includes two other fields / columns and you can refer to these in a textbox by setting the control source of the textbox to:
= MyCombo.Column(2) ''Lastname
Where you count columns from zero:
Row Source : ID (0), Firstname (1), Lastname (2)
Cascading combos are another story altogether, and you can read it here How to synchronize two combo boxes on a form in Access 2002 or in Access 2003 and here Is there a simple way of populating dropdown in this Access Database schema?

Auto populating text boxes on an Access 2003 form when value selected in combo box

I am building a form in access database.
I have a combo box which is linked to a query which is looking up a unique reference number from a table called Tbl_Submitted_Requests.
What I need the form to do is auto populate the other text boxes when the user selects the unique reference from the combo box. How can I get the text boxes to auto populate with the data that is associated with each unique reference?
Thanks
First, bind your form to Tbl_Submitted_Requests or better, a query that uses this table, you can do this with the form wizard or by setting the Record Source property of the form. Each of the textboxes will also need to have a control source set to the name of a field (column) Next, add a combo and choose "Find a record on my form based on the value I select in my combobox" from the wizard options.
I will agree with Remou's response, with one small edification. Crate a new form, and drag all of the fields from the relevant query or table onto this form. Alternatively, you can drag them from the field chooser if the form has already been bound. Then, create your combo-box, and choose "Find a record on my form based on the value I select in my combobox" from the wizard options.