Update form in access when form is not open using VBA - forms

I developed a form in Access that allows users to search for records that match their parameters. The form has about five combo boxes that contain values which a user can search. A query is set up that pulls the values from the combo boxes. An associated form, "F_FilterResults", lists the results of the query as a datasheet that display the results of the search. I created an AfterUpdate event on each combo box on "F_FilterResults" so that after I update the combo box with a search parameter the query and form would refresh itself. Here's some sample code from the AfterUpdate event in the combo boxes on "F_FilterResults".
Private Sub CompanyState_AfterUpdate()
Forms![F_FilterResults].Requery
Forms![F_FilterResults].Refresh
End Sub
This only works however if the "F_FilterResults" form is open. When it is closed I get Run-time error '2450' message that indicates that the "Microsoft Access cannot find the referenced form 'F_Filter.' How can I have this code run when the "F_Filter" form is not open? Note I do not want the form to open right after you select a search parameter from a combo box since the user may want to add more search parameters to the other combo boxes. If I program "F_FilterResults" to open on loading the search form the user may X out it and would not know what the error message means.

You can open a form hidden. That is the "easy" answer. However the need to do this means that the way you go about achieving your result is not the best.
The way I would do it is that instead of updating a form that pulls values off the combo boxes I would generate a string that can be applied as a filter to the form when it is opened.

Related

Repeatable Form elements

I need to allow the users repeat some of the form fields(or form groups) in the survey forms. There should be a + or - button next to the field that if the user clicks on +, then a new field is created.
Example: https://www.rhyzz.com/repeatable-fields.html
I would be surprised to know if Qualtrics doesn't have this feature.
I google for this but no success.
You can't create new fields (choices, answers, variables, etc.) on the fly in Qualtrics. A field has to be defined in the survey for it be be saved in the response data.
You could write a JavaScript to show and hide fields to give the appearance of adding and removing fields, but you would have to define the maximum number of fields in the survey beforehand.

MS-Access: How to create form where user can add results (tblResults) to a tests (tblTests)?

I am creating a database that contains Product information (tblProductInfo), a list of test methods (tblTests), and the results that the product gets (tblResults).
I'm adding forms so that a user can enter the results of a previous or new product. This information will be added once all the testing for that product is done. So, I would like to be able to show a list of the tests from tblTests, and have the user enter the results in a text box of some sort displayed directly next to the tests. I can't figure out a way to do so, where it will then save all the results that the user entered.
I have created a form with a subform, where the subform shows the 2 columns (tests and results) and when I change it to allow DataEntry, it gets rid of all the test names. I need it to keep the test names displayed, but allow entry in the results column.
Any ideas?
Below is a screenshot of an example of what I would like, although I need the Results column to be empty.
Create a continuous subform with only the tblresults as the recordsource, and for the header or each field of results use the related test as the label is how I would do it. Set allow additions to yes, allow edits to no allow deletions to no.

Adobe Acrobat form fields are all auto completing

In Acrobat preference I have auto complete turned off.
When I fill in one form field, all of the other form fields are filled in too with the same word?
So if I enter 'hello' into one field all the other form fields on the questionnaire get the value 'hello'.
I copied and pasted the form fields for each question to save time, surely that doesn't mean each form field in the questionnaire is just one form field, or does it?
How can I separate each form field so it can hold its own answer?
I found an answer to my question.
Fields with the same name will automatically get the same value, so each form field needs a different name.
If you create one form field, then right click on the form field in the menu on the right and choose 'place multiple fields', you can then input how many fields you want for the form along with other options. Acrobat then names each form field separately for you.

Combobox governing subform possibly updating tables

I have a form, the form is bound to a query which returns only one field. On that form is one combo box, bound to the field from the query, a subform object and some other unimportant stuff. The Master-Child relationship between the Form and Subform is set to that same field. The intent is that dropping down the combo box allows me to add information on the subform pertaining to that record in the combobox (it's a list of classes in a school, for context). This is done through a form and subform as I have various different tasks that need to be done for each class - the intent is to be able to select a class on the main form and then use command buttons on it to select which subform is opened depending on which task I wish to perform.
However, the Combo box appears to be trying to update a table - I'm not sure which one as the error message isn't specific:
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key or
relationship. Change the data in the field or fields that contain
duplicate data, remove the index or redefine the index to allow
duplicate values and try again
appears if I select any value other than the first one from the combo box and then click in the first text box on the subform. However, I can click in the subform with the first entry in the combo box selected and add data successfully, I've checked and it is appearing in the underlying tables.
It seems to me, as a relative novice in Access, that the combo box is attempting to update the underlying data source when it is changed, though it has no macros. I would assume there are items in the properties of the form or the combobox that prevent that from happening but I can't find them. That is just a guess as to what's happening, though, and I could be wrong.
It's possible that this is related to this question but I could be mistaken there as well. Regardless, the Form shouldn't be able to update/edit/add records but if I set Allow Edits in its properties to "No" I am unable to actually select a value from the combobox - I have set the other "Allow" properties to "No" without a problem.
If you change anything in the main form and then click on the subform then Access will try to save the data in the main form automatically. Maybe you can try to temporally exchange the combo box with a text field for testing. That should help you to clarify the problem.

MS Access 2003 findfirst method doesnt work in Load() event of form

After a few days of frustration, I have decided to present this issue here for resolution. Searches through countless forums and help sites have not presented any similar issue. The following details the problem with a FindFirst method in MS Access 2003:
Tables and Forms: Customer Info Table > Service Details Table as a one-to-many relationship with referential integrity and cascading updates enabled (there may be more than one service detail for each customer). A search form allows user to select ‘customer’ and ‘service provider’ (a field in table Service Details) sending that information to open a main form/subform to enter service data related to ‘customer’ using ‘service provider’ (text string) as criteria. There may be more than one ‘service provider’ per ‘customer’ (i.e. each Service Detail entry may have a different ‘service provider’ for the same ‘customer’).
Objective: The main form (with subform, both based on select queries) should open to the specified record/subrecord.
Current Method: A combo box on the main form (not the search form) allows user to select appropriate ‘service provider’ using the FindFirst method (combo box created by wizard). This works but not what is intended. The ‘service provider’ criteria is initially selected in the search form and passed into the main form (as a global variable for now), so the combo box selection on the main form becomes redundant and could cause confusion for the user (they could accidentally enter data for the wrong service details).
Problem: I assumed copying the code from the AfterUpdate() event of the combo box to the Load() event of the main form would be adequate, but it does nothing, no errors, just loads the first available Service Details record instead of the selected one using ‘service provider’ as criteria.
Tests: I have inserted message boxes to check the criteria value for the ‘service provider’ selected, and everything seems ok, both in and out of the FindFirst method inserted in the Load() event of the main form. I have tried a DLookup(), DoCmd.Findrecord and setting the default of the combo box to the criteria passed from the search form, but still only the first ‘service provider’ record is displayed, instead of the one selected in the search form.
Code:
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Service Provider] = '" & [g_serviceProvider] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
This produces no errors, and hovering over the g_serviceProvider variable with the mouse in debug mode shows the correct string value. This code works perfectly in the AfterUpdate() event of the combo box, but does nothing when inserted into the Load() event of the form, even though the values are indeed passed (checked using message boxes to display data at each stage of the execution).
I am at a loss of why this only works for the combo box but not in the Load() event of the form. I suspect the problem is in the recordsource of the form (select query), as the recordsource of the combo box uses a SELECT expression based on the same query as the form. I have had no success with coding the recordsource to use with the FindFirst method within the Load() event, as that produces errors (cannot find any relevant examples to work from). Any ideas? Thanks in advance.
Ok, I finally figured it out. The actual problem was the form loading the Current() event multiple times when opening the form to a specific record. This was happening on pretty much every form where an existing record is being displayed. It seems to be an artifact of the form opening and record selection of MS Access 2003 (don't know about newer versions, but I have read several other posts concerning this issue).
There is a dirty work around, by using a count of the number of times the Current() event runs when a form is opened. I have found that for a "virgin" form (blank form ready to accept input with blank record source (table)) the Current() only runs one time. If there is any existing records, but the form is blank ready to input a new record, the Current() will run twice. When displaying a record that already exists that must populate a form, the Current() will run three times before all of the data loads enough to make the selection through coding rather than through a combo box (which loads with the control). Subform Current() seems to run one more time than the parent form.
To check to see if and how many times any event occurs, insert a simple message box in the suspected block of the form's VBA code.
Creating a simple counter, coded in the Current() event block of the main form, solved the problem.