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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update default to last entered value 1

Status
Not open for further replies.

WVTexan

Technical User
Nov 19, 2001
4
US
ok... just learning VB code... which is why I'm having trouble with this... I've figured out most of my other issues already.

I'm trying to make a form that when a value is changed, the default for that field changes to the value that was last entered.

sorry for the ignorance... but my learning curve is happily steep so there wont be too many dumb questions.

thanks in advance, and Happy Thanksgiving,
IPJ
 
If you mean, when a Form goes to a new record the field should come preloaded with the last value that was entered then you could refer to the OldValue of the field on the forms current event. This should work.

Sub Current()
if me.NewRecord then
me.myfield = me.myfield.OldValue
end if
End Sub
 
Well, once I got it to stop giving me errors, it still didnt do anything. But... I have the code in the on_current event of the form. here's what I have:

Private Sub Form_Current()
If Me.NewRecord Then
Me.block_size = Me.block_size.OldValue
Me.length = Me.length.OldValue
Me.width_field = Me.width_field.OldValue
end if
end sub


even when I fill in the form and go to the next record, nothing happens.


do I have to have it in the on_current for each field? if so, how do I make it a public statement that I can write once and call for each field? i.e. how do I get it to recognize the current field it's on. I believe I'd have to dim a variable called "field_im_on_now" (or something) and then set that to the name of the current field. correct? if so (or if not) what's the VB code to this?

thanks,
Ian J
 
Hi!

If you have a date stamp or an autonumber for the PK then you can use the DLast function:

=DLast("YourField", "YourTableOrQuery")

Alternatively, you may be able to set up a query which will always order the records in input order and use the DLast statement with that query as the domain.

hth Jeff Bridgham
bridgham@purdue.edu
 
would this work?

Public Sub AfterUpdate(fieldname As String)

Set Me.fieldname.DefaultValue = Me.fieldname.Value

End Sub


then I would call this procedure in the after-update event of each of the fields I need this for as
"AfterUpdate(length)" or "AfterUpdate(width)" or "afterUpdate(block_size)"
--> how do I call these procedures from the after update event field in the properties box... when I reference this, it says it cant find a macro. Do I have to write somehting like this for each field on hte form?

here's another stupid question... this all goes into the form's code right... it doesnt go into another module that I make separately does it?


TIA,
Ian

PS. thanks Jeff and cmmrfrds for the first round of this
 

I GOT IT!!!!!

here's what I've done... it's kinda a pain, cause I have to write the procedure for each of the fields I need this for but this works:

Private Sub block_size_AfterUpdate()
Me.block_size.DefaultValue = """" & Me.block_size.Value & """"
End Sub


thanks for at least getting me on the right path.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top