Previous record as default value? (1 Viewer)

scottay

New member
Local time
Today, 08:57
Joined
Jan 9, 2007
Messages
9
Is it possible for me to specify the default value in a table as what was inputed in the previous record?
 

sdawson

Registered User.
Local time
Today, 16:57
Joined
Apr 22, 2003
Messages
165
Ctrl & ' will bring down the value of that field from the previous record.

Not sure if that helps?
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:57
Joined
Feb 28, 2001
Messages
27,191
Two issues.

1. Sdawson is correct about CTRL/apostrophe.

2. Otherwise, there IS no previous record. (The Matrix: "There is no spoon...")

This is because in SQL, which is the basis for the JET engine's operation, the word PREVIOUS doesn't truly have a universal meaning. SQL is based on set theory, where the elements are theorized as unordered members of selection sub-domains (hence the term "Domain Aggregate").

On a FORM (or a datasheet, which is an implied form), there is a "PREVIOUS" because the form imposed an order. But the CTRL/apostrophe does what it does DESPITE / OUTSIDE OF set-theory domain concepts.

So there is no SQL function for "previous record's value" because in standard SQL, "previous" and "next" don't exist conceptually.

You can do "PREVIOUS" and "NEXT" via VBA using temporary variables or opening the recordset twice. You can do it on a form because bound controls usually have a "previousvalue" attribute. But you can't do it in SQL.
 

scottay

New member
Local time
Today, 08:57
Joined
Jan 9, 2007
Messages
9
Thank you both for your replies. I am aware of the ctrl + ' and am currently using that. Just looking for a way to have that automatic instead of having to do the key combo in each of the 4 places I need it every time I make an entry. Just a note, this isn't for a web application, so I'm not using any SQL. This is just a local database that I'm using to keep track of the lubrication schedule for a piece of equipment (You may have seen my other post regarding that, but I figured that part out).
 

Oldsoftboss

AWF VIP
Local time
Tomorrow, 01:57
Joined
Oct 28, 2001
Messages
2,499
Making the next field in records default to the last record.
We will base this on a field called UserName...

In the After Update event of the UserName field put code like this:

Me![UserName].Tag = Me![UserName].Value

In the On Enter Event of the same field put code like this:

If Not Me.NewRecord Then Exit Sub
If Not (IsNull(Me![UserName].Tag) Or Me![UserName].Tag = "") Then
Me![UserName].Value = Me![UserName].Tag
End If


The UserName will not carry over into your next session with the form but will work as long as the form is open....

Add the code to the fields you want to update, just change the code to reflect the field names.

Dave
 
Last edited:

Bat17

Registered User.
Local time
Today, 16:57
Joined
Sep 24, 2004
Messages
1,687
or even just
Me![UserName].defaultvalue = Me![UserName].Value
in the after update will do it (I think :) )

Peter
 

Oldsoftboss

AWF VIP
Local time
Tomorrow, 01:57
Joined
Oct 28, 2001
Messages
2,499
Never tried that, but you may be right.

The code above is something I keep in a folder of misc Access stuff. I know it works, so I just go with that.
 

boblarson

Smeghead
Local time
Today, 08:57
Joined
Jan 12, 2001
Messages
32,059
I could be wrong, but I thought I had tried that with that other post (from which my example came) and so we went about it using an unbound text box and just changed the text box if the value in the applicable field changed to something other than was in the text box.
 

Bat17

Registered User.
Local time
Today, 16:57
Joined
Sep 24, 2004
Messages
1,687
had a quick look :)
It works on a text field if you wrap in quotes. Probably need to do something similar with dates but have not tested it.

Me.InputText.DefaultValue = "'" & Me.InputText & "'"

Peter
 

themurph2000

Fat, drunk, and stupid
Local time
Today, 10:57
Joined
Sep 24, 2007
Messages
181
had a quick look :)
It works on a text field if you wrap in quotes. Probably need to do something similar with dates but have not tested it.

Me.InputText.DefaultValue = "'" & Me.InputText & "'"

Peter


Works beautifully. Thanks.
 

ROY_Z

New member
Local time
Today, 21:27
Joined
Sep 16, 2012
Messages
3
Hi,
Is it possible to add a value to existing value every time. For. e.g. Value 1+ previous Value = (Value 1 + previous value) and next time Value 1 + (Value 1 + previous value)= Value 1 + (Value 1 + previous value) and so on by up dating
 

Users who are viewing this thread

Top Bottom