Setting default value on the fly

B

Bruce

I have a database for recording training information.
There is a main form to record session information
(subject, instructor, etc.), and a subform to record
attendance. The form and the subform are each bound to
their own table. The subform's table is a junction table
between the Employees table and the Sessions table (each
session has many attendees; each employee attends many
sessions). The subform (and its underlying table) has
fields for name, date, and a check box
labeled "Verified". I would like a way of having the
default value of the check box be "No", but with a way of
setting the check box value to "Yes" for all attendees.
The reason is that sometimes the manager will set up in
the database a training session for a specific listed
group of employees, in which case attendance is not
verified until later, when the session is complete. In
other cases the training record will be handwritten, in
which case attendance can be verified as the training
session is being entered into the database. I know I can
set the default value of the check box in the table, but I
would like to be able to change it on the form (with a
command button?), so that in the second case mentioned
above (handwritten record), all names entered will
automatically have a check mark in "Verified".
In a possibly related question, I would like for the
default date next to each employee's name to be the same
as for the previously listed employee at that session.
90% of the time that is the case; sometimes, though,
because of different shifts, etc., it is not, which is why
I cannot just put the date into the general session
information.
 
K

Kevin Sprinkel

One way to handle the verification is to include a command
button to toggle the default value. Set your default
value equal to True in form design mode. In the OnClick
event of the command button:

Me!YourCheckBoxControlName.DefaultValue = _
Not Me!YourCheckBoxControlName.DefaultValue

For the date, one easy way is to set the default value in
the field's AfterUpdate event:

Me!YourDateControlName.DefaultValue = _
Me!YourDateControlName

HTH
Kevin Sprinkel
 
B

Bruce

Thanks for the suggestion. The check box in question is
on a subform, but the command button is on the main form.
It took me a while to work that out. Your suggestion has
the effect of toggling the default value, which would be
fine if I could figure out how to reset it to True each
time I start a new record. I expect that some variant of
the code you suggested (except that it would be = True
instead of repeating the control name) would go into some
event or other, but I haven't yet figured out which one.
Your second suggestion had the curious effect of making
the next field Dec. 30, 1899 instead of the previous
field's May 05, 2004. Every field thereafter defaulted to
Dec. 30, 1899. Curiouser still, when I clicked into the
19th century date it said 6:00:00 AM. When I clicked out
it reverted to the date. Perhaps if the default date
could default to the value of the date for the previous
record? If I could get code to look at the PK of the
current record, then find the record with a PK one less
than that, and take the date from that record, something
like that might do it. Not sure how it would respond if
there was no previous record (i.e. it had been deleted).
I am using autonumber rather than some sort of calculated
incrementing, so it could happen. Anyhow, it's Friday
afternoon, and I am done for the day. Thanks again. If
you have any further thoughts on any of this, I look
forward to hearing about it.
 
B

Bruce

I answered the first part of my question by placing Me!
YourCheckBoxControlName.DefaultValue = True into the
form's On Current event. The date question continues to
vex me. I don't know if you are still monitoring this
thread, so i will start a new one with just the date
question. Thanks again for your help.
 
K

Kevin Sprinkel

Bruce,

Oops! I forgot to type the retrieved date value.

S/B

Me!YourControlName.DefaultValue = "#" & Me!YourControlName
& "#"

HTH
Kevin Sprinkel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top