What is the difference between bound and unbound controls in MS Access?
How do they differ? And when on an MS Access Form in design view, how can we tell if a form is bound or not?
Bound elements are linked directly back to the relevant tables, and when you amend any data within form's, your changes are immediately written to the tables. This can often lead to people questioning why "when I close a form does it save the changes?" Well that's bound behaviour for you, and to prevent any updates you must use procedures such as BeforeUpdate to cancel if necessary. Bound controls are easy to identify as they will contain the field names from the table in design view.
Unbound forms are quite the opposite, they are not tied directly to database fields and involve more coding work in order to initially populate them in normal view. However these will not automatically make changes to your tables without a custom procedure you have written e.g. a Save button. This allows a little more control, but also involves more work and good understanding of VBA coding. Unbound controls are also easy to identify as they will contain the word unbound in design view.
Note: There is much more can be said but this is a basic outline.
A bound control is one that is bound to a field in a table or to a function. An unbound control has no Control Source property, similarly, a bound form has no Record Source. You can check the property sheet.
Related
I have created a database with one form and one table. The form is basically an application and asks questions about each person/applicant. I've written skip logic/conditional formatting in different events for disabling/enabling certain questions or text; as well as used Access's built-in Conditional Formatting for enabling and disabling text fields and other controls.
For times when I want to disabled Checkboxes, Access's conditional formatting is not an option for this type of control, so I have written VBA code to disable these checkboxes based on the lead-in questions, which works great. The issue that I am having is that if I finish an applicant and some fields have become disabled as a result of my VBA, when I create a new record, those fields remain disabled, whereas, the fields that I used the Conditional Formatting tool are reset correctly.
Its my understanding that I will need to write some code to reset these controls for when there is a new record. I wasn't sure which Form event to use. Also, I want to preserve what has been enabled and disabled as I review records. So if I go back to a record where a checkbox was disabled, it remains disabled, etc.
You want to use the Form_Current event. This event fires once each time you go to a record.
As a result, it fires in the following situations:
When you open the form
When you move to an existing record
When you move to an empty record
What is the right way to do some calculation in MS access to be stored in the bound table through the user entry form
Should I make use of VBA or simply from access.
You can make simple calculations directly in a textbox for instance. If you set the control source to something like "=A*B", you will see the result of A * B in the textbox. However, in VBA you can write more complex functions that you can reuse (even from textboxes "=MyFunction(A,B)").
In VBA Functions you can store intermediate results in variables, perform loops and so on. You can even implement some error handling. This is not possible otherwise.
It makes your application easier to maintain, if you keep the code in a central place in modules, compared to spreading the calculations over dozens of controls in forms and reports.
The general rule is that you should not store calculations. If you must write a calculation to a bound textbox, you will have to use VBA. If you are using MS Access 2010, you can make use of calculated columns.
I'm experimenting with Reports in MS-Access 2003 and I have to ask what value is there, if any, to adding interactive controls to a Report? This includes Command Buttons, Checkboxes, etc that are made inactive once the Report is viewed in its proper Print Layout.
I'm opposed in general to the use of user interface controls on reports, but it actually is an advantage that you can save a form as a report. That's one reason you could end up with interactive controls on a report.
Arguably, one can also justify combo boxes and option groups, the first because it saves a join in the report's recordsource (which might cause complications or performance issues), and the second because it provides not just an indication of the stored value, but also what it means and what the other options are.
Check boxes I see no issue with at all. They are a good way of indicating Boolean values.
Command buttons I can't justify, but are likely supported simply for the compatibility issue that allows you to save a form as a report.
I would like to create an Access report in which the record source is created via ADO code and then set as the record source for the report when the report is run. The problem I am running into is how to add fields to the report since the recordset is bound to the report at run-time and not design time. Is there way I can manually add the field and make sure the field name matches what will be provided in the recordset field collection? Thank you.
The standard solution to this problem is to add all your fields in design view, up to the max available, and hide all of them, and show only the ones you need. Michael Kaplan explained that when he designed the Access Replication Conflict Resolver, this is the approach he used, precisely because adding controls at runtime quickly uses the lifetime limit on the number of controls on a form (700+, but I can't recall the exact number).
It's also just a bad idea, as #Jeff O says, to do design changes at runtime. For one, it means you can never distribute an MDE.
Several ways to do it, but all of them have their issues. create-dynamic report using vba
Other questions have found the folley in working in design mode programatically.
I have an old Access database that is being upgraded to work with Access 2007. The client is complaining that it is slow now. I am looking for ways to optimize it.
There is one subform that is in a particular tab on the form. I have been wondering -- does the subform still update/query even when it is not visible?
If this is configurable --- how?
All controls refresh/update whether visible or not.
It's generally considered good practice to not load recordsets until they are needed. If you have many subforms in a tab control, you can use the tab control's OnChange event to load/unload your subforms, or, alternatively, to set the recordsources.
However, with only a couple of subforms, this is not likely to be a big help. But with a half dozen or so, it's a different issue.
You can remove the recordsource from the subform and add it back when the form is made visible, or simply remove the whole subform and add that back.