Select Last added Row

simmoz

New member
Local time
Today, 16:53
Joined
Jan 11, 2007
Messages
6
Hi
This should be fairly simple but I cannot figure it out.

I have a Form which I have added a button to ADD a new item, which in turn opens up another Form.
However after entering all the necessary field and closing / re-querying I would like it to select that last entered item as default. I tried messing with macro's but to no avail. Here is the code for exiting from entering a new item..

Private Sub CABLE_TYPE_SELECT_exit_Click()
DoCmd.Close acForm, "Cable_Type_Select"
DoCmd.OpenForm "CABLE ENTER"
With Forms![CABLE ENTER]
.SetFocus
.Requery
End With
End Sub

thanks for any help!!
Simmo
 
If you have an autonumber field in the table you can simply search for the highest number available, this will allways be the newest record.

Alternatively you could make a public variable that stores your PK inbetween forms and search for it.
 
Do you know the code to select cable_no where autonumber = highest ?
trying to avoid having to do a search function after entering:confused:
Sorry I'm new to this..

n.b. Cable_no is my PK and the report is Grouped by this hence no good to use this because the last entered cable_no could be 350th of 3000 for example
 
Just make a public variable in any Module.
Fill this value on leaving the popup form and search for it when returning...
 

If you have an autonumber field in the table you can simply search for the highest number available, this will allways be the newest record.

This is not a true statement. It is MOSTLY correct, but if someone is using replication this will NOT be correct. If using replication an autonumber will generate a UNIQUE number, but not in any numeric order. In fact you will get one number like -235948839 and then get one right afterwards of 5493993.

I just wanted to make sure that everyone is aware that an autonumber doesn't always move in consecutive order.
 

Users who are viewing this thread

Back
Top Bottom