Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make Default Value the Previous Records field value 1

Status
Not open for further replies.

iowabuckmaster

Technical User
May 21, 2003
36
US
I am trying to write an expression in a default value for a field to make it equal the Previous Records field value. Can this be done and how, because I'm not getting it. Thanks for any help.

A day in November is worth 5 in October
 
in the after update of the control

Me.controlname.DefaultValue = Me.controlname.Value
 
In the property sheet for strCity, in the After Update, I have the following:

Me.strCity.DefaultValue = Me.strCity.Value

I then want to go to a new record in form and have the city field populated with the city from the previous record.

It did not work for me. What am I missing.

A day in November is worth 5 in October
 
this is not for the propety sheet this should be entered in

Code:
Private Sub strCity_AfterUpdate()
Me.strCity.DefaultValue = Me.strCity.Value
End Sub
and in the propety sheet

Code:
[Event Procedure]
 

Actually, that syntax will only work for Numeric values. The syntax varies, depending on datatype of the field.

For Text fields

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

For Numeric fields

Code:
Private Sub YourNumericControl_AfterUpdate()
If Not IsNull(Me.YourNumericControl.Value) Then
  YourNumericControl.DefaultValue = Me.YourNumericControl.Value
End If
End Sub

For Date fields

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



The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Title Bar follows:
Microsoft Visual Basic - Forms -[Form Personal Data(Code)]

Option Compare Database
________________________________________________________
strCity AfterUpdate

Private Sub strCity_AfterUpdate()
Me.strCity.DefaultValue = Me.strCity.Value
End Sub

When I go to new record I get #Name? in the city field.

When I start typing in a field in the new record the #Name? goes away, when I finish the record the city field is blank.

A day in November is worth 5 in October
 
Replace this:
Me.strCity.DefaultValue = Me.strCity.Value
with this:
Me!strCity.DefaultValue = Chr(34) & Me!strCity.Value & Chr(34)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
No further progress

Title Bar follows:
Microsoft Visual Basic - Forms -[Form Personal Data(Code)]

Option Compare Database
________________________________________________________
strCity AfterUpdate

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


Again,
When I go to new record I get #Name? in the city field.

Again
When I start typing in a field in the new record the #Name? goes away, when I finish the record the city field is blank.

Note:
In properties the Name and Control Source are both strCity.

When I go to the new record I want the City from the previous record to populate the the new records city field. Maybe through the default Value is not where I should be doing this? I am still stuck!!!!!!


A day in November is worth 5 in October
 
I have used a Public variable as in
Code:
Option Compare Database
Public PostMatHold As String

Private Sub Form_Load()
...
populate with after update as above (I used the value at the end of Sub Form_Current as the value is not editable.)

As long as the form is open it has the value.
Good Luck,
djj
 
The code posted here by myself and PHV (his second code) are valid and both test out OK for me. I couldn't reporduce your probelm no matter what I tried. The one thing I wonder about is this stray bit at the top of your posted code; what exactly are the strCity and AfterUpdate doing here? Are they actually in your code as it shows here? If so it needs to be removed.


strCity AfterUpdate

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

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
How are ya iowabuckmaster . . .

Perhaps my post in the following thread thread702-1382356 will do! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
The code posted here by myself and PHV (his second code) are valid and both test out OK for me."

And they work for me, now.

Some where as I ran different pieces there was a value in my Default Value field. I took that out and both codes work. Not sure how it got there. Sorry. Thanks all for your patience.

"The one thing I wonder about is this stray bit at the top of your posted code; what exactly are the strCity and AfterUpdate doing here?"
They were not in the code I had these listed to show the Object and Procedure Names.

I now have a Did You Know... for my newsletter and another for next month on Repeating the Last Record.

Thanks All




A day in November is worth 5 in October
 
Hi there.

This works if you are inputting records one after another. However, how would you have the default value of the field the same as the entry for the previous record for when you open the form?

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top