Pretty simple explanation. I have a table with 10 entries, 5 entries with the year 2010 and 5 entries with 2011 in a column.
In the query I have, I use Like *2010 to filter out all entries equal 2010 and display onl those records.
On my form, I have combobox being populated with each unique year (from a different table). So my combobox values are 2010 and 2011.
Is it possible, when I select say 2011, I trim the right 4 characters and use as my Like criteria to refresh and requery the form, all done within VBA?
You can refer to the value of a control in a query run from within an Access session, as long as the form which contains that control is open.
SELECT *
FROM YourTable
WHERE date_field_as_text Like "*" & Forms!YourForm!YourCombo;
So perhaps you can use a similar query as your form's record source, and do Me.Requery in the combo box's after update event.
If that's not close enough to what you want, please give us more information about the data types of the fields involved. Adding brief samples of the table data to your question could also help; please make it clear whether the "date" fields are text or Date/Time.
Yes, it's possible.Just add your stuff to the 'YourComboName.After_Update'.
Look for the Events of the Form that are fired before the form is shown. There build your query as like HansUp suggested.
Related
I'm trying to create a database in Access 2010, and have run into a bit of a problem. I currently have two tables, EarlyStageListResults & ESDailyTotals. Each of these tables has a field named Records, with ESDailyTotals being a summary of multiple entries in EarlyStageListResults. What I need to do is have the Records field in ESDailyTotals be the sum of multiple Records fields in EarlyStageListResults. For example, given the following records in EarlyStageListResults:
Date Records
4/22/16 2000
4/22/16 3000
4/22/16 1500
4/21/16 1200
4/21/16 2700
the records in ESDailyTotals should be:
Date Records
4/22/16 6500
4/21/16 3900
I know this can be calculated later through VBA and a form event, but optimally I'd like to be able to have it update as soon as any of the Records fields in EarlyStageListResults changes. It looks like there may be a way to do this using the Access Macro Editor (not sure of the name, but the tool where you can create a macro through a series of combo boxes rather than through VBA), but I've never gotten an understanding of using that tool, so have always relied on Forms and VBA instead. Basically if there's an event that triggers when a field is updated, and a way to enter VBA code into that event handler like you can with Access Forms, then I can do it with either DLookup or an SQL statement I think, but I don't know how to grab that event handler.
This does all need to be done within Access itself, I can't use an external program to update the records in an Access database file. This is for work, and (officially at least) any custom programs are a big no-no. :)
Thanks in advance everyone!
You're making this way too complicated. You just need one table and a database view (called a query in Access, I think) that is defined as
select Date, sum(Records) as Records from EarlyStageListResults
group by Date
Name the query ESDailyTotals.
I just started to use Access with vba. I have table with roles, years and its workload of each role in this specific year. Each record in the table is IDRole, IDYear,Workload (number).
I display the table in a form doing a crosstab table where the years are in the columns and the roles in the rows. The number of years can increase.
My problem is when I add new years and display in the columns, it doesn't appear in the form so I have to select from the field list manually but I would like to know if there is any way in VBA that when the form is load, automatically appears the new columns (years).
I misunderstood your situation. Your form's crosstab data source is actually a table instead of a query. And as you add columns to that table, you want the new columns to automatically appear in the form when you next open the form.
In that case, use the approach described below, but where I selected a query (Query.qryFoo2) in the Source Object dropdown, choose your table ... Table.YourTableName ... in that dropdown.
The last 2 paragraphs below apply whether your data source is a table or query.
If you have your crosstab query saved as a named query, you can use it as the Source Object for a subform control.
Then when you switch from Design to Form View, the query results will be displayed in Datasheet View within the subform control.
As the number of columns changes over time, that Datasheet View can "automagically adapt" to display them ... the same as if you opened the named query directly in Datasheet View.
As far as I'm aware, there is no other reasonably simple way to accomplish what you want. If this suggestion is not suitable, you can explore programmatically adding bound data controls to your existing form after examining the set of fields the query currently returns. But that is way too much effort IMO.
I have exactly the same issue, I have a form which I use to show a Query, And I can't anticipate the number of columns from the query.
I found the same topic on other pages, and for the moment the only way I found is to build an excel file based on the query.
Another way also is maybe to directly open the crossTab query using vba.
I have a form that has multiple comboboxes. Some of them allow multiple values and some of them don't. One of the comboboxes that allows multiple values is causing duplicate entries in the form records.
I can't find any differences in the property sheet between the combobox that isn't working and those that are.
Example fields in the form:
Patient Account Number
Date of Admission
Location of Patient (combobox that allows multiple values; working correctly)
Interface Used (combobox that allows multiple values; working correctly)
Interventions (combobox that allows multiple values; NOT working correctly)
When I select more than one Intervention it duplicates the record within the form. I have 5 patients entered into the form, but one of them has 3 Interventions selected. So instead of showing "1 of 5" records at the bottom of my form I see "1 of 8" and 3 of them are exactly the same. When I look at my parent table though, there are still only 5 records.
Please forgive me if I didn't call something the proper name. I'm very new to Access. Thank you! I tried to add screenshots, but I don't have enough reputation points.
I suspect that the form's underlying query (=RecordSource) is using the Value property of the multivalue field. If so, remove Value from the query.
view the query's SQL and look for the word .Value
remove the word Value and the period before it then re-run the query the results will change back to normal amount of records and so will your form or report.
I am fairly new to Access. I am trying to create a filter pre-report form. On this form, the user will be asked for a start and end date. He will also be given a list of Item names which are found in a different form/table and will have the ability to check off which items the report should filter on.
Do I need to use a subform for this? I tried one out, but I can't see how to add checkboxes, it seems to just give me a list and I can't modify the subform.
What I really think I need to do is to populate a checkbox list with all of the items in the other table. How exactly would I do this (if its really the best solution)?
You can use a regular form for this. You do not need to bind it to a table. Just drop 2 textboxes on the form, and as many checkboxes as you feel you need.
The report will be based on a query, which in turn will be based on this form. All the fields will be brought into the query and will reference the controls on the form.
For instance, let's say you have 2 textboxes on the form; one called txtStartDate and one called txtEndDate. The form will be called frmReportFilter. In the query that's driving the report, pull in your date column and in the Criteria put >=Forms!frmReportFilter!txtStartDate. This will pull in all records where your date field is greater than or equal to whatever is in the Start Date textbox. The rest will be referenced similarly.
I have a report which lists 2 fields namely appointments and absences. Now what I want is that after building the report, I want to get the difference between these 2 counts. Is that possible?
thanks!
If your report has two fields on it, Appointments and Absences, and they are named the same, create an unbound control and assign its ControlSource to be this:
=[Appointments]-[Absences]
Now, I wouldn't really recommend using that, since it's likely that the controls and the fields they are bound to have the same name. I'd rename the control that is bound to Appointments as txtAppointments and the one bound to Absences as txtAbsences, and the calculation would then be [txtAppointments]-[txtAbsences].
Now, keep in mind that this assumes that neither field is ever Null. If it is, you probably want this, instead:
=Nz([txtAppointments], 0)-Nz([txtAbsences], 0)
Try and see if it works!