Need to automaticallu input date in form

M

mhudson

This seems to be a very popular question posed on the forum, and I have read
through and tried the most viable solutions given to others. I have three
diferent forms that update a table with three different date fields. Although
I have set the default value for all the date fields in the table to =Date()-
1, this only works on one of the forms, even though that field in each form
is given same properties.

The forms are used to update an inventory table containing part numbers, wip
dates and amounts, packing dates and amounts, and shipping dates and amounts.
I use the three different forms because not all the same part numbers have
records in each category each day. I typically update the tables the next day,
hence the Date()-1. This works well during the week, but not on Monday or if
I skip a day and have to enter data from more than one day ago.

The better solution would be to have a box on the form into which I could
input the date for the transactions being made, which would then
automatically fill in the date for the individual transaction. Is there a
reasonable way to do this? Thanks.
 
M

missinglinq via AccessMonster.com

If you're saying you want to sit down, enter the first transaction record for
a given day and enter the date, then have that date automatically filled in
for each ensuing record until you start entering records for another date (
and change the date manually to start the new series of records) then you can
use the DefaultValue property of the control on yur form holding the date.

Private Sub YourDateControlName_AfterUpdate()
If Not IsNull(Me.YourDateControlName.Value) Then
YourDateControlName.DefaultValue ="#" & Me.YourDateControlName & "#"
End If
End Sub

where YourDateControlName is the actual name of the textbox holding your
transaction date. After entering the date, it will automatically fill in the
each record thereafter until you manually change the date. Then it will start
over again and do the same thing with the new date.
 
M

mhudson

missinglinq said:
If you're saying you want to sit down, enter the first transaction record for
a given day and enter the date, then have that date automatically filled in
for each ensuing record until you start entering records for another date (
and change the date manually to start the new series of records) then you can
use the DefaultValue property of the control on yur form holding the date.

Private Sub YourDateControlName_AfterUpdate()
If Not IsNull(Me.YourDateControlName.Value) Then
YourDateControlName.DefaultValue ="#" & Me.YourDateControlName & "#"
End If
End Sub

where YourDateControlName is the actual name of the textbox holding your
transaction date. After entering the date, it will automatically fill in the
each record thereafter until you manually change the date. Then it will start
over again and do the same thing with the new date.


Excellent, excellent, that did exactly what I wanted it to do. Seeing as how
I am still a greenhorn at Access, once I figured out that the code goes into
the VB editor for the control for the form (not your fault!) everything
worked just like I want it to. Thanks for your quick response and a great
solution!
 
T

TotallyConfused

Hi I have been trying to achieve the same for a db. I am new to vb how do
you set Default Value? . Can this work on a subform? Woudl the same code
work. My text box is text. Thank you.
 

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