Opening form with specific record displayed

Y

Yakman

I have a form displaying a list of term dates. The table containing the list
has a field "CurrentYear", this is either "Yes" or "No". How can i display
only the "Yes" record when opening the form.
 
A

Alfred

Base your form on a query and set the criteria field in the query
(Currentyear) to true
Alfred
 
D

Dirk Goldgar

Yakman said:
I have a form displaying a list of term dates. The table containing
the list has a field "CurrentYear", this is either "Yes" or "No". How
can i display only the "Yes" record when opening the form.

As an alternative to Alfred's perfectly reasonable suggestion, if you
open the form in code you can specify a criterion in the WhereCondition
argument of the DoCmd.OpenForm method. For example,

DoCmd.OpenForm "frmTermDates", _
WhereCondition:="CurrentYear = True"

That assumes that your CurrentYear field is a yes/no, or boolean, field.
If it's actually a text field containing the literal string value "Yes"
or "No", then this would be a better example:

DoCmd.OpenForm "frmTermDates", _
WhereCondition:="CurrentYear = 'Yes'"
 
Y

Yakman

Thank you for your reply.
I used

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmTermDates", _
WhereCondition:="CurrentYear = 'Yes'"
End Sub

and this works, but i tried using it on the "On Open", "On Load" and
"Before Update" but this will only display the CurrentYear='Yes' records. If
i add next years term dates, i would like to be able to display these also.

Thanks
Yakman
 
D

Dirk Goldgar

Yakman said:
Thank you for your reply.
I used

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmTermDates", _
WhereCondition:="CurrentYear = 'Yes'"
End Sub

and this works, but i tried using it on the "On Open", "On Load" and
"Before Update" but this will only display the CurrentYear='Yes'
records. If i add next years term dates, i would like to be able to
display these also.

Thanks
Yakman

I'm not at all sure I understand what you're saying. Are you talking
about putting the code in the Open event of the form that is displaying
the term dates -- "frmTermDates" in my example code? That's not the way
I intended it, and the code is overkill for that purpose.

I assumed that you wanted the form to normally display all records, if
you just opened it from the database window, but that you wanted a way
to open the form from, say, a command button, and in that particular
case show only the current year's records. If this is not what you had
in mind, you'd better explain exactly what you have now and what you
want, in more detail. I get the feeling that you may only need a way to
filter the form for "CurrentYear = 'Yes'", and to turn that filter on
and off at will, but I'm really not sure.
 
Top