Default value of field in current record to be value of last recor

G

Guest

I am new to VBA and am learning. But I need to get beyond this problem to
get up and running.

I want to be able to allow the user to enter a date in a field on a form
(call it a posting date) in the first record of the data-entry-session (not
necessarily the first record in the underlying table). Once that is done, I
want the subsequent new record to be able to use the date from the user's
first record as the default value for the current (new) record.

If the user should change the date after, say the third or fourth record,
the program should remember the new date and make it the new default value
for the user's next (new) and subsequent records until it is changed again by
the user.

I don't seem to be able to find any literature on this 'ditto' dillema!
I would appreciate any input on this problem. Thanks in advance.
 
A

Allen Browne

Use the AfterInsert event procedure of the form to set the DefaultValue
property of your date text box.

The DefaultValue is a string type property, so it will end up looking
something like this:

Private Sub Form_AfterInsert()
With Me.[NameOfYourDateControlHere]
If Not IsNull(.Value) Then
.DefaultValue = "=""" & .Value & """
End If
End With
End Sub
 
M

Marshall Barton

Frank said:
I am new to VBA and am learning. But I need to get beyond this problem to
get up and running.

I want to be able to allow the user to enter a date in a field on a form
(call it a posting date) in the first record of the data-entry-session (not
necessarily the first record in the underlying table). Once that is done, I
want the subsequent new record to be able to use the date from the user's
first record as the default value for the current (new) record.

If the user should change the date after, say the third or fourth record,
the program should remember the new date and make it the new default value
for the user's next (new) and subsequent records until it is changed again by
the user.

I don't seem to be able to find any literature on this 'ditto' dillema!
I would appreciate any input on this problem.

Use the date text box's AfterUpdate event to set its
DefaultValue property to its new value:

Me.textbox.DefaultValue=Format(Me.textbox,"\#m\/d\/yyyy\#")

The reason for the Format function is because the
DefaultValue property is a string value and you need to use
the # to make sure Access converts the string back to a date
correctly.

Don't forget that users can hit the shortcut key combination
Ctrl + " to duplicate the corresponding field from the
previous record.
 
G

Guest

i've got a form in my a2k app'n with a field called "Patient Number". once
the enterer's entered the first instance of this (filtered for) value it
seems a good idea to ask the app'n to reprise it on the next and subsequent
records entered. would this approach work for me. what does the 'With' syntax
stand for?

thanks for any help.

-ted


Allen Browne said:
Use the AfterInsert event procedure of the form to set the DefaultValue
property of your date text box.

The DefaultValue is a string type property, so it will end up looking
something like this:

Private Sub Form_AfterInsert()
With Me.[NameOfYourDateControlHere]
If Not IsNull(.Value) Then
.DefaultValue = "=""" & .Value & """
End If
End With
End Sub
 
G

Guest

hi, on the surface all this seems straightforward and quite simple.

my field's a combobox called [Patient Number] on my a2k app'n.

what'd the syntax look like?

tia,

-ted
 

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