I have a form that allows a user to view every record in the database (one at a time) via a combobox. The combobox displays a 'recordID' which is not the primary key and can (will) therefore have duplicates. The 'recordID' is reset back to 1 every calendar year.
There are 3 different ways to load the 'View Everything' form. One is via command button which opens the form to the most recent record. Another is to double click a listbox entry to open the form to the selected record. And finally, clicking the previously mentioned command button with an item selected in the listbox will open the form to that record.
Regardless of which way you enter the form, the combobox on the form will let you move around to different records.
What I'd like to do on the 'View Everything' form is filter the results of the combobox by year, with it defaulting to the year of the record that was selected or to the current year if the form was opened without a record selected. I'd also like to provide the user with a way to change which year is available via the combobox - presumably with another combobox.
My current code:
with a selection (command button with something selected and double clicking use the same code)
and without a selection
[HiddenID] is the primary key and [EmailID] is the visible 'recordID' I mentioned earlier.
So, my initial thoughts to accomplish the first goal of filtering the available records to a single year were to add a filter to the above code. But when I look at the properties sheet of the form, my Where condition from the code above is being used the filter. I think I may be a little confused about the difference between a filter and a Where condition when it comes to the property sheet display.
Is something like
or
even possible?
Would that even be the right way to go about this?
Some other thoughts I've tossed around:
-Creation of a recordset on form load to restrict what's available, but I have no experience with recordsets and I'm not even sure if that's their intended purpose.
-Adding code to the combobox to restrict what is listed in it.
I don't know if either of those methods are viable or how I'd implement them, but I'm just brainstorming right now.
Hopefully I've articulated my goals and the landscape within which I'm working well enough. Any thoughts or ideas would be most appreciated.
There are 3 different ways to load the 'View Everything' form. One is via command button which opens the form to the most recent record. Another is to double click a listbox entry to open the form to the selected record. And finally, clicking the previously mentioned command button with an item selected in the listbox will open the form to that record.
Regardless of which way you enter the form, the combobox on the form will let you move around to different records.
What I'd like to do on the 'View Everything' form is filter the results of the combobox by year, with it defaulting to the year of the record that was selected or to the current year if the form was opened without a record selected. I'd also like to provide the user with a way to change which year is available via the combobox - presumably with another combobox.
My current code:
with a selection (command button with something selected and double clicking use the same code)
Code:
DoCmd.OpenForm "frmViewEmail", acNormal, , "[HiddenID] = " & Forms!frmHome!listAllEmail.Column(0) & ""
Code:
DoCmd.OpenForm "frmViewEmail", acNormal, , "[EmailID] = " & DMax("EmailID", "tblEmails", "year([ReceivedDate]) = " & Year(Date))
So, my initial thoughts to accomplish the first goal of filtering the available records to a single year were to add a filter to the above code. But when I look at the properties sheet of the form, my Where condition from the code above is being used the filter. I think I may be a little confused about the difference between a filter and a Where condition when it comes to the property sheet display.
Is something like
Code:
DoCmd.OpenForm "frmViewEmail", acNormal, year([ReceivedDate]) = Year(Date), _
"[EmailID] = " & DMax("EmailID", "tblEmails", "year([ReceivedDate]) = " & Year(Date))
Code:
DoCmd.OpenForm "frmViewEmail", acNormal, year([ReceivedDate]) = year(Forms!frmHome!listAllEmail.column(3)), _
"[HiddenID] = " & Forms!frmHome!listAllEmail.Column(0) & ""
Would that even be the right way to go about this?
Some other thoughts I've tossed around:
-Creation of a recordset on form load to restrict what's available, but I have no experience with recordsets and I'm not even sure if that's their intended purpose.
-Adding code to the combobox to restrict what is listed in it.
I don't know if either of those methods are viable or how I'd implement them, but I'm just brainstorming right now.
Hopefully I've articulated my goals and the landscape within which I'm working well enough. Any thoughts or ideas would be most appreciated.