Open specific record of form

bknight
BronzeLounger
Posts: 1391
Joined: 08 Jul 2016, 18:53

Open specific record of form

Post by bknight »

I didn't see this anywhere. I have a query that feeds a form.

Code: Select all

SELECT (Year([Filled])) AS [Year], (Month([Filled])) AS [Month], Sum(Trades.Dividends) AS Dividend
FROM Trades
GROUP BY (Year([Filled])), (Month([Filled])), Trades.Type
HAVING ((((Year([Filled])))=2024) AND ((Trades.Type)="Dividend"));
There is a code to open the form once the main form opens

Code: Select all

Private Sub Form_Load()
    DoCmd.OpenForm "frmOpenPositionsFirst", view:=acFormDS
    DoCmd.OpenForm FormName:="frmDividends", view:=acFormDS
    DoCmd.OpenForm FormName:="frmDivByMonth", view:=acFormDS
    DoCmd.OpenForm FormName:="frmDivByMonth_Previous_Year", view:=acFormDS
    DoCmd.SelectObject acTable, , True
    DoCmd.Minimize
End Sub
The command is " DoCmd.OpenForm FormName:="frmDivByMonth", view:=acFormDS"
It opens and the first field of the first record is displayed, I guess by default.
So I would like the form to pen displaying the third field in the last record.
what commands would be best to make this happen?

User avatar
HansV
Administrator
Posts: 78511
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open specific record of form

Post by HansV »

Let's say the control bound to the third field is named Dividend.
Below the line

Code: Select all

    DoCmd.OpenForm FormName:="frmDivByMonth", view:=acFormDS
insert:

Code: Select all

    DoCmd.GoToRecord Record:=acLast
    Forms!frmDivByMonth!Dividend.SetFocus
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1391
Joined: 08 Jul 2016, 18:53

Re: Open specific record of form

Post by bknight »

I'll try that tomorrow morning.

bknight
BronzeLounger
Posts: 1391
Joined: 08 Jul 2016, 18:53

Re: Open specific record of form

Post by bknight »

OK, worked great.
Thanks

User avatar
HansV
Administrator
Posts: 78511
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open specific record of form

Post by HansV »

Good to hear that.
Best wishes,
Hans