last row entered (1 Viewer)

ryetee

Registered User.
Local time
Today, 14:48
Joined
Jul 30, 2013
Messages
952
I have a form where the user can add as many rows as he wants - it's usually only 1 or 2 but that's not the point.
When he has finished editing he clicks a Save and Exit button.
In here I want to save data from the last row he has entered. I have this working but only if the cursor remains on the last row or on the 'new' record row. If he manages to, say, put his cursor on the penultimate row then I save the data for that.

eg.

Col1.........Col2..........Col3..............Col4
AA...........AAA...........AAAA.............AAAAA
BB...........BBB...........BBBB.............BBBBB
CC...........CCC...........CCCC.............CCCCC
DD...........DDD.........DDDD.............DDDDD
EE...........EEE............EEEE.............EEEEE
NEW LINE

So I for instance want to save Col3 on the last line filled in. Lets say the control is called Col3 then

If the cursor is on NEW LINE I have got the code so that
Me.Col3 "EEEE"
If the cursor is on the last line (the 5th) I have got the code so that
Me.Col3 "EEEE"
If the Cursor is on the first line i get "AAAA", "BBBB" for the 2nd etc tc
How do I always pick up the last line?
 

Minty

AWF VIP
Local time
Today, 14:48
Joined
Jul 26, 2013
Messages
10,371
Is this an unbound form?
If not I would simply force the focus to a new record before exiting ?
 

ryetee

Registered User.
Local time
Today, 14:48
Joined
Jul 30, 2013
Messages
952
No it's bound to a query and yes it seems that DoCmd.GoToRecord , , acLast works fine

Thanks
 

jdraw

Super Moderator
Staff member
Local time
Today, 09:48
Joined
Jan 23, 2006
Messages
15,379
You could have a EnteredDate as a Date/Time field(default NOW), and sort the records.
SELECT * from tableX where EnteredDate =(Select Max(EnteredDate) form TableX);

Just a thought --maybe there's more to your question.
 

ryetee

Registered User.
Local time
Today, 14:48
Joined
Jul 30, 2013
Messages
952
You could have a EnteredDate as a Date/Time field(default NOW), and sort the records.
SELECT * from tableX where EnteredDate =(Select Max(EnteredDate) form TableX);

Just a thought --maybe there's more to your question.
I've got i working now using the above but thanks!
 

Users who are viewing this thread

Top Bottom