How Do I Insert Value from one Field into a different field

G

Guest

I have a database that contains both starting and ending mileages.
What I would like to do is have the data entry from show the default entry
for the starting mileage be the ending mileage from the last record.

I also need to be able to override this default in case the number changes
for some reason.

I have tried a Dlookup function and have not had any luck.

Nicole
 
G

Guest

On the form Load event you can set the default

Me.starting.DefaultValue = DlookUp("Start FieldName","TableName","[Key
fieldName] = " & DMax("[Key fieldName]","[TableName]"))

Me.ending.DefaultValue = DlookUp("End FieldName","TableName","[Key
fieldName] = " & DMax("[Key fieldName]","[TableName]"))
=================================
The Dmax is used to bring the last record entered, you need to change the
[Key fieldName] to the name of the field that indicate which field was the
last to be entered.
=================================
On the After update event of the form, you need to add the code that check
if the value changed, if it did, it will change the default

If Me.starting.DefaultValue <> Me.starting Then
Me.starting.DefaultValue = Me.starting
End If
If Me.ending.DefaultValue <> Me.ending Then
Me.ending.DefaultValue = Me.ending
End If
 
G

Guest

Use an unbound textbox on your data entry form that pulls the last mileage.
Then have your bound textbox (starting mileage) default to the value in the
unbound textbox.
 
P

Phillip Windell

In the Form's "OnLoad" event use the following Select statement pattern to
get the startmilage from the Record with the highest Date.

SELECT Top 1<startmileage> FROM <table> ORDER BY <date> ASC

Then apply it to the value of the Text Box on the Form, something along the
lines of:

txtStartMileage.text = <startmileage>

My knowledge of VB and SQL is "generic" in nature and my knowledge of the
specifics of Access is limited. Sorry I can't be more specific than this,
but it should point you in the right direction.
 

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