DLast Issue

D

David Whitaker

I am trying to retrieve the last entry from a field in a record reguardless
if it was the last record or the record previous to that. I am using this;

Private Sub Form_Current()
If IsNull(me.begininv) or me.begininv = "" Then
me.begininv = (DLast("[onendinv]","[pump]"))
End If
End Sub

The problem is is that it doesnt work.
I have tried;

Private Sub Form_Current()
me.begininv = (DLast("[onendinv]","[pump]"))
End Sub

and it still doesnt work.
Any ideals as to why its not working, Am I using the wrong variant?
 
R

Rob Oldfield

What do you mean by "it doesn't work"? 'Pump' is a table or a query?
'Onendiv' is a field within that? What goes wrong?
 
J

John Vinson

I am trying to retrieve the last entry from a field in a record reguardless
if it was the last record or the record previous to that. I am using this;

Private Sub Form_Current()
If IsNull(me.begininv) or me.begininv = "" Then
me.begininv = (DLast("[onendinv]","[pump]"))
End If
End Sub

The problem is is that it doesnt work.

DLast() is an all but useless function. It returns the last record *IN
DISK STORAGE ORDER* - and you have absolutely no control over that
order! DLast() will not necessarily be the last or most recently
entered record; that record might have gotten put anywhere within the
table, if you've had any deletions.

Could you explain what constitutes the "last" record in your case? Do
you have some timestamp or sequential autonumber field which would let
you find it?

What you might want to do to set the default value of begininv to the
most recently entered record's onendinv is to put code in the onendinv
control's AfterUpdate event:

Private Sub onendinv_AfterUpdate()
Me!begininv.DefaultValue = Chr(34) & Me!onendinv & Chr(34)
End Sub


John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 

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

Similar Threads

StrWhere? 1
Add New Record 3
lastName & firstName using DLAST 8
Usage of DLAST 5
DoCmd.RUNSQL INSERT Queries 4
Help with simple code getting frostrated 4
Multiple Criteria 2
proper code placement 4

Top