Default Value

  • Thread starter Thread starter Floyd Forbes
  • Start date Start date
F

Floyd Forbes

I have a form in which one field is called date. The dates
entered are often the same for a period of time so I would like the
default value for this field to be the same as the last entered date.
Can anybody please help me with how to do this.

Thank you
 
Floyd Forbes said:
I have a form in which one field is called date. The dates
entered are often the same for a period of time so I would like the
default value for this field to be the same as the last entered date.
Can anybody please help me with how to do this.


You have received two replies to this question in the newsgroup already.
Have you read and considered those replies? You do understand that
questions asked in newsgroups are answered there, not by email?
 
I too am trying to do this. I have tried both
recommendations without success. I would be grateful if
someone could explain how to do it in step by step
instructions. I am a novice, a retiree doing volunteer
work for charitable organizations -- trying to help those
who help others, so I appreciate both your your patience
and assistance.
 
Chinagroveh said:
I too am trying to do this. I have tried both
recommendations without success. I would be grateful if
someone could explain how to do it in step by step
instructions. I am a novice, a retiree doing volunteer
work for charitable organizations -- trying to help those
who help others, so I appreciate both your your patience
and assistance.

Please describe your form, name the control on which you are attempting
to do this, and tell the name and data type of the field to which it is
bound. Also please post the code you've tried and explain exactly what
kind of "non-success" you've encountered: did nothing happen? Did
something happen, but not what you had in mind? Did you get an error
message?
 
The form has four fields from a table:"ADS(names of
donation stations are stored)", "Date (Medium date
format)", "Time (short time format)", and "Qty (Quantity
for number of donors per date time period)"

The control name is "Date" and it is Date/Time data type.

Here is code I typed in as I understood your instructions:
Option Compare Database

Private Sub Form_AfterUpdate()
With Me![Date]
..DefaultValue = Format(.Value, "\#mm/dd/yyyy\#")
End With
End Sub

Private Sub Date_BeforeUpdate(Cancel As Integer)

End Sub

I appreciate your willingness to try to help
 
The form has four fields from a table:"ADS(names of
donation stations are stored)", "Date (Medium date
format)", "Time (short time format)", and "Qty (Quantity
for number of donors per date time period)"

The control name is "Date" and it is Date/Time data type.

Here is code I typed in as I understood your instructions:
Option Compare Database

Private Sub Form_AfterUpdate()
With Me![Date]
.DefaultValue = Format(.Value, "\#mm/dd/yyyy\#")
End With
End Sub

Private Sub Date_BeforeUpdate(Cancel As Integer)

End Sub

I appreciate your willingness to try to help

That looks to me as though it ought to work, at least to do what I
thought was wanted, so long as the property sheet for the form specifies
"[Event Procedure]" on the Before Update line on the Event tab. The
empty Date_BeforeUpdate procedure isn't doing anything (unless you just
failed to copy the code), and should be deleted.

What this code should do, and does for me, is capture the date I just
entered in the control and set that as the control's default value for
the next record. Is it not doing that for you? The code will not set a
default value until the first time you save a record in the current
editing session with the form -- if you want it to set a default value
when the form is first opened, more code must be written. Also, the
code is not intended to pick up the most recent date ever entered in the
table; it's just supposed to pick up what you enter, each time you
enter something, and make that the default value for the next record.
 
Indeed it works!! I did not have "[Event Procedure]" on
the Before Update line on the Event tab set. I am most
grateful to you.

Will this work for non date fields as well? e.g.,
Goodwill is also entering the name of donation stations
repetively as they enter data. If so, what change need I
make to the code. Name of the control is "ADS" and it is
a lookup field, which I think is number type data -- I
created a combo box so they can pick the ADS vice
keyboarding.

Again, many thanks for sharing your expertise.
-----Original Message-----
The form has four fields from a table:"ADS(names of
donation stations are stored)", "Date (Medium date
format)", "Time (short time format)", and "Qty (Quantity
for number of donors per date time period)"

The control name is "Date" and it is Date/Time data type.

Here is code I typed in as I understood your instructions:
Option Compare Database

Private Sub Form_AfterUpdate()
With Me![Date]
.DefaultValue = Format(.Value, "\#mm/dd/yyyy\#")
End With
End Sub

Private Sub Date_BeforeUpdate(Cancel As Integer)

End Sub

I appreciate your willingness to try to help

That looks to me as though it ought to work, at least to do what I
thought was wanted, so long as the property sheet for the form specifies
"[Event Procedure]" on the Before Update line on the Event tab. The
empty Date_BeforeUpdate procedure isn't doing anything (unless you just
failed to copy the code), and should be deleted.

What this code should do, and does for me, is capture the date I just
entered in the control and set that as the control's default value for
the next record. Is it not doing that for you? The code will not set a
default value until the first time you save a record in the current
editing session with the form -- if you want it to set a default value
when the form is first opened, more code must be written. Also, the
code is not intended to pick up the most recent date ever entered in the
table; it's just supposed to pick up what you enter, each time you
enter something, and make that the default value for the next record.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
Indeed it works!! I did not have "[Event Procedure]" on
the Before Update line on the Event tab set. I am most
grateful to you.

Excellent! You're welcome.
Will this work for non date fields as well? e.g.,
Goodwill is also entering the name of donation stations
repetively as they enter data. If so, what change need I
make to the code. Name of the control is "ADS" and it is
a lookup field, which I think is number type data -- I
created a combo box so they can pick the ADS vice
keyboarding.

Yes, it will work, but you have to modify it according to data type.
Better yet, here's a version that will work for *all* data types:

Private Sub Form_AfterUpdate()
With Me![YourControlNameHere]
.DefaultValue = """" & .Value & """"
End With
End Sub

Just insert the name of the control in place of "YourControlNameHere".
 
Here is code, but I get error msg that "ambiguous name
detected: Form_AfterUpdate"
Option Compare Database

Private Sub Form_AfterUpdate()
With Me![ADS]
.DefaultValue = """" & .Value & """"
End With
End Sub

I also put ADS between """", but that did not work
either. Does the lookup field cause this? [Event
Procedure] is in Before Update field of Event. Date
still works.

Thanks


Private Sub Form_AfterUpdate()
With Me![Date]
..DefaultValue = Format(.Value, "\#mm/dd/yyyy\#")
End With
End Sub

-----Original Message-----
Indeed it works!! I did not have "[Event Procedure]" on
the Before Update line on the Event tab set. I am most
grateful to you.

Excellent! You're welcome.
Will this work for non date fields as well? e.g.,
Goodwill is also entering the name of donation stations
repetively as they enter data. If so, what change need I
make to the code. Name of the control is "ADS" and it is
a lookup field, which I think is number type data -- I
created a combo box so they can pick the ADS vice
keyboarding.

Yes, it will work, but you have to modify it according to data type.
Better yet, here's a version that will work for *all* data types:

Private Sub Form_AfterUpdate()
With Me![YourControlNameHere]
.DefaultValue = """" & .Value & """"
End With
End Sub

Just insert the name of the control in place of "YourControlNameHere".

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
Chinagroveh said:
Here is code, but I get error msg that "ambiguous name
detected: Form_AfterUpdate"
Option Compare Database

Private Sub Form_AfterUpdate()
With Me![ADS]
.DefaultValue = """" & .Value & """"
End With
End Sub

I also put ADS between """", but that did not work
either. Does the lookup field cause this? [Event
Procedure] is in Before Update field of Event. Date
still works.

That message means that you have two procedures with the same name:
"Form_AfterUpdate". And it happens because you already had an event
procedure for the form's AfterUpdate event (presumably the one you added
to deal with the [Date] control), and pasted the whole routine above
into your form's code module. Because you already had a
Form_AfterUpdate event procedure, you should have just added the lines
*between* the "Private Sub" and "End Sub" lines -- and not including
those lines -- to the existing procedure.

To fix it:
Remove the second AfterUpdate event procedure, so there's only the old
one in the form's module. Then go to that old procedure and insert the
following lines before the End Sub line:

With Me![ADS]
.DefaultValue = """" & .Value & """"
End With

So now the procedure looks something like this:

'----- start of procedure -----
Private Sub Form_AfterUpdate()

With Me![Date]
.DefaultValue = Format(.Value, "\#mm/dd/yyyy\#")
End With


With Me![ADS]
.DefaultValue = """" & .Value & """"
End With

End Sub

'----- end of procedure -----

That ought to do the job. Make sure, after you're done modifying the
event procedure, that the form's AfterUpdate event property still reads
"[Event Procedure]".
 
Works perfectly!! A final thank you for your
assistance. I hope others note your professional and
considerate manner in patiently guiding me to the desired
solution. And I pray you receive personal satisfaction
and reward through your generosity.
-----Original Message-----
Here is code, but I get error msg that "ambiguous name
detected: Form_AfterUpdate"
Option Compare Database

Private Sub Form_AfterUpdate()
With Me![ADS]
.DefaultValue = """" & .Value & """"
End With
End Sub

I also put ADS between """", but that did not work
either. Does the lookup field cause this? [Event
Procedure] is in Before Update field of Event. Date
still works.

That message means that you have two procedures with the same name:
"Form_AfterUpdate". And it happens because you already had an event
procedure for the form's AfterUpdate event (presumably the one you added
to deal with the [Date] control), and pasted the whole routine above
into your form's code module. Because you already had a
Form_AfterUpdate event procedure, you should have just added the lines
*between* the "Private Sub" and "End Sub" lines -- and not including
those lines -- to the existing procedure.

To fix it:
Remove the second AfterUpdate event procedure, so there's only the old
one in the form's module. Then go to that old procedure and insert the
following lines before the End Sub line:

With Me![ADS]
.DefaultValue = """" & .Value & """"
End With

So now the procedure looks something like this:

'----- start of procedure -----
Private Sub Form_AfterUpdate()

With Me![Date]
.DefaultValue = Format(.Value, "\#mm/dd/yyyy\#")
End With


With Me![ADS]
.DefaultValue = """" & .Value & """"
End With

End Sub

'----- end of procedure -----

That ought to do the job. Make sure, after you're done modifying the
event procedure, that the form's AfterUpdate event property still reads
"[Event Procedure]".

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
Chinagroveh said:
Works perfectly!! A final thank you for your
assistance. I hope others note your professional and
considerate manner in patiently guiding me to the desired
solution. And I pray you receive personal satisfaction
and reward through your generosity.

Thank you for your courtesy.
 
Back
Top