Show last value

T

Tommy2326

Is there any way I can set a text box to show the entry from the last record
on a blank form? I've set my form up so that when it opens there is no data
visible, however one of the text boxes will contain the exact same data over
a period of time and it would be easier if the operators only had to enter it
once. Is it possible to do this?

Thanks for the help

Tommy
 
K

Klatuu

Yes. In the After Update event of the control, set its Default Value to the
current value of the control.
 
S

Sharif

I have the same problem, which is I need the date box to show the last date
entered for the previous record, since it is repeated several times before a
different date has to be entered.

I copy pasted the following code:
Me.ControlName.DefaultValue = Me.ControlName
in the afterupdate box, with my control box name ofcourse, but I got the
error:
Micr. Off. Access can;t find the object 'Me'

Truth said I am not a programmer so I would really appreciate any detailed
response if it involves code or macro since I have tried 4 responses to
similar problem with different codes and just couldnt get it to work.

Any help is very appreciated.

Thanks,
Sharif
 
L

Linq Adams via AccessMonster.com

The syntax is slightly different, depending on the datatype of the data:

For Text fields

Private Sub YourTextControlName_AfterUpdate()
If Not IsNull(Me.YourTextControlName.Value) Then
YourTextControlName.DefaultValue = """" & Me.YourTextControlName.Value &
""""
End If
End Sub

For Numeric fields

Private Sub YourNumericControlName_AfterUpdate()
If Not IsNull(Me.YourNumericControlName.Value) Then
YourNumericControlName.DefaultValue = Me.YourNumericControlName.Value
End If
End Sub

For Date fields

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

The .Value is included for clarity's sake, but can be omitted, of course,
because it is the Default Property for textboxes.
 
S

Sharif

Hello again,
I really appreciate your detailed response, but I must be doing something
wrong.. I hope for more of your and everyone's patience, this is what I am
doing:

In the property sheet of the controlbox of concern, I go to afterupdate,
select code builder, and paste the code you sent in your email (and many
other from other responses to similar problem I have), close the code builder.
Go back to access, save the form, change to form view and try entering
records but the controlbox of concern doesnt retrieve the last date when a
new record is entered.

Any help or advice is appreciated. Sorry for the inconvenience.
Sharif
 
Top