Sorry, I had skimmed this post quickly and missed the fact that you'd
discovered the same resolution I proposed.
As to why you can't get it to work immediately after opening the form, it's
because Access is "slightly" multi-threaded and the form is being opened
asynchronously. You're issuing your command before the form recordset is
populated, so the "move to last record" command is useless at this point.
It would be an unreliable way of doing it, but if you put in some kind of a
delay loop after your OpenForm command, you'd probably find that the "move
last" would take effect normally if you delayed long enough.
A third way of doing this, which is less common, but useful in some
circumstances, would be to open the form by creating a new instance of it
instead of through OpenForm. I'm just writing this off the top of my head,
but the code would look something like this:
Private Sub Edit_Data_Click()
Dim f As [Form_Product Details Ver1]
'need square brackets because name has spaces
Set f = New [Form_Product Details Ver1]
DoCmd.GoToRecord acDataForm, f.Name, , acLast
End Sub
I *believe* that when you do it this way, the Set statement only returns
after the form is fully loaded. I might be wrong in that, though, in which
case the code gets a bit more complicated, and I won't confuse you with
facts unless you need them.
(To give you an outline, though, you either have to issue an f.Requery or
similar statement, which is redundant, but forces the form to fully
populate, or you have to use event sinking in order to catch the Form_Load
event outside of the form itself...possibly useful, but if you can do it in
the regular Form_Load event, then there's no reason to do it this way.)
Rob
Hi Bob,
Firstly, thanks for taking the time to answer. It is much appreciated.
The record source table has a primary key index which is a number. I want to
be able to identify the last record number used (not a new record).
My aim is to then add 30 numbers and then print a page of sticky labels for
the 30 new numbers added. (I think that I can achieve this but if I run into
problems then I might post some more questions).
Previously the numbers were created on the labels by hand and then simply
added individually as new records but unfortunately people make mistakes
writing them out by hand and it is a major task to correct them.
Since posting my question, I have found a workaround by putting the
following code in the form "On load" event:-
DoCmd.GoToRecord , , acLast
The above works fine. However, I would still like to know why I cannot
insert the code immediately after the following line when I open the form:-
DoCmd.OpenForm stDocName, , , stLinkCriteria
What am I missing or not understanding here?
I am reasonably competent in VBA for Excel but have a great deal to learn
about Access.