View Full Version : Forms defaults to record which contains system date


jharley
02-12-2002, 05:57 AM
Hope somebody can help.

I have a database where 1 field in a table contains short dates. When I open a form based on this table, I would like the form to automatically default to the record whose date field = today's date (i.e. system date).

Sohaila Taravati
02-12-2002, 07:19 AM
Try putting this in your control source of your text box:
=Date()


Sohaila

David R
02-12-2002, 11:58 AM
Errrr, depending on what you want to do that will not work.
Do you want to jump to the existing record that was started today? Put =Date() in the query underlying your form, or in the WHERE clause of the OpenForm statement.
Do you want the field, when a record is first opened, to start with today's date, and store it in your table as a datestamp? Put Date() in the Default Value of the Control. Lock the field if you want it to be unchangeable by the user.
Do you want to display an unbound text box with today's date? Sohaila's suggestion will work for that.

HTH,
David R

David R
02-13-2002, 07:51 AM
Passing on this response-by-email because I think there's a better way to tackle this:

Thanks for the response to my question: I have a database where 1 field in a
table contains short dates. When I open a form based on this table, I would
like the form to automatically default to the record whose date field =
today's date (i.e. system date).


I don't think I explained it quite correctly. The table that the form is
based on has a field called Date. This is a short date and already has dates
entered into it (i.e. 12/02/02, 13/02/02, and so on........) - sorry it's in
UK format! There are actually 1419 records which takes it to the date
31/12/05. I have created a query so that the dates are sorted in ascending
order - the form is based on this query. So the idea is, when somebody opens
the form (let's say on 15/04/02 for example) - the form will open on the
record whose date field contains the value 15/04/02.

I should imagine it is a very simple procedure. Unfortunately I have no
programming skills whatsoever - which makes life difficult. I would be very
grateful if you could help.


First off, Access uses Date as a reserved name (see below), you should not name controls or fields Date.

If you're using Macros, I'm sure there's a way to do this, but I don't know the exact syntax. In code it is fairly painless:
In whatever event you're using to open the form (Click event of a command button, AfterUpdate of a combobox, etc), put something similar to this:
DoCmd.OpenForm "FormName", , , [DateField] = Date
This should work as long as your date field is an actual Date/Time type field. As for the larger problem of structure, I can't tackle it today, hopefully someone else can. I'm not sure pre-filling your table with dates for several years is the best solution.

HTH,
David R


[This message has been edited by David R (edited 02-13-2002).]