Go to last record in Subform

G

Guest

I have the following problem.

I have a table with data of customers. I also have a table with orders. The
two tables are linked by a customer number. I designed a form with the
customer data and in the form is a subform with the orders. If I change the
customer the corresponding orders can be viewed and edited in the subform.

If I change the customer I want to go to the last record in the subform.
Therefore I wanted to use the code: DocCmd.GoToRecord acForm, "Subform Name",
acLast.

VBA gives me an error that the Subform is not opened.

How can I solve this problem.

Thanks in advance,

JeroenM.
 
A

Allen Browne

That's correct: the subform is not open in its own right (i.e. it is not
part of the Forms collection.)

Instead, use the RecordsetClone of the form:

Dim rs As DAO.Recordset
If Me.Dirty Then Me.Dirty = False
Set rs = Me.RecordsetClone
If rs.RecordCount > 0 Then
rs.MoveLast
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
 
G

Guest

Thanks,

But where do I have to place the VBA code? What event of the (sub)Form do I
use?

JeroenM.

"Allen Browne" schreef:
 
A

Allen Browne

Where did you plan to use your GoToRecord code?
In the click event procedure of a command button, perhaps?
 
G

Guest

I use the lookup function (binoculars symbol) to find the right customer. I
also have some buttons in the form but they are rarely used. In the subform
(where I want to go to the last record) are no buttons.

JeroenM.

"Allen Browne" schreef:
 

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