Go to Record....

Q

qpurser

Hi,
I have a mainform "orders" and a subform "orders by cust."
First I select on the mainform the name of a cust....In the subform I
get all the orders the cust. did.
Now I have a button on the mainform "Invoice preview".
How can I make it possible that I preview the last record from the
subform automatically.
For now I always had to move the cursor to the last record, otherwise
I would always get a preview from the first record in the subform...
THX for any help
Mike
 
E

Eric Butts

Hi,

You would have to select (or move) to the last record on the subForm.

Here's what you could try behind your command button:

- say the name of the subForm Control is "mysubFormControl"
IMPORTANT: not concerned about the name of the Sub Form

- In the Visual Basic Editor window select the menu option Tools >
References and make sure "Microsoft DAO 3.6 Object Library" is checked.

- Sample code
Private Sub Commandbutton3_Click()
' declare a recordset object
Dim rst As DAO.Recordset

' make the recordset object equal to the RecordsetClone
of the
' subForm control
Set rst = Me.mysubFormControl.Form.RecordsetClone

' for the recordset move to the last record
rst.MoveLast

' open Report with where clause that compares against the
recordset object
DoCmd.OpenReport "Report1", acViewPreview, ,
"[ProductID]=" & rst!ProductID

' destroy the Recordset object
Set rst = Nothing

End Sub


I hope this helps! If you have additional questions on this topic, please
respond back to this posting.

Regards,

Eric Butts
Microsoft Access Support
 
Q

qpurser

Thx Eric,
It works.....
The only thing I had to do was instead of
Set rst = Me.mysubFormControl.Form.RecordsetClone
I had to change it to:
Set rst = Me.[mysubformControl].Form.RecordsetClone

Onec again...many thnks
 

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