Opening query(s)

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

Opening query(s)

Post by bknight »

I open certain forms on a Db with code. Is there a methos to open queries as well?

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

Re: Opening query(s)

Post by bknight »

Oops this should be in a new thread.

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

Re: Opening query(s)

Post by HansV »

I have moved these posts to a new thread
Best wishes,
Hans

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

Re: Opening query(s)

Post by HansV »

In general, end users should never view tables and queries directly.
But if you really want to, just like you can open forms using DoCmd.OpenForm, you can open queries using DoCmd.OpenQuery.
Best wishes,
Hans

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

Re: Opening query(s)

Post by bknight »

Well I'm the only user, but thanks.

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

Re: Opening query(s)

Post by bknight »

I do have a small issue with one of my Dbs. When the Db is opened there is a form that is loaded with the Application Options. I entered the following code into an OnLoad event of the form

Code: Select all

Private Sub Form_Load()
DoCmd.OpenForm "frmTDAmeritradeExDates"
DoCmd.OpenQuery "quUpcomingExDates"
DoCmd.OpenQuery "quSymbolFilter"
End Sub
The fir command opens that form in design view instead of Datasheet view(my preference)
Any suggestion to open that form in datasheet view? This an annoyance rather.

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

Re: Opening query(s)

Post by HansV »

Try

DoCmd.OpenForm FormName:="frmTDAmeritradeExDates", View:=acFormDS
Best wishes,
Hans

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

Re: Opening query(s)

Post by bknight »

HansV wrote:
07 Apr 2023, 18:09
Try

DoCmd.OpenForm FormName:="frmTDAmeritradeExDates", View:=acFormDS
That was successful. This is a different command than similar commands in all the other Dbs I have. Is this a better command for all of them?

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

Re: Opening query(s)

Post by HansV »

If you want to be sure that a form is opened in Datasheet view, you can use this. If you want to open a form in Form view, use acNormal instead of acFormDS.
Best wishes,
Hans

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

Re: Opening query(s)

Post by bknight »

Ok. Other questions in the same theme of opening.
What would be a code command to open the application with the navigation panel hidden?
What would be the code to open a form or query Top = XXX, Left = xxx. For my screen only not to be distributed.

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

Re: Opening query(s)

Post by HansV »

1) Click the big Office button, then click the Access Options button at the bottom.
Select Current Database.
Scroll down to the Navigation section.
Clear the check box Display Navigation Pane.
Click OK.

The database will now open with the navigation pane hidden.
Press F11 to unhide it.

2) Use code like

DoCmd.OpenForm FormName:="frmTDAmeritradeExDates", View:=acFormDS
Forms("frmTDAmeritradeExDates").Move Left:=400, Top:=300

No idea how to position a query.
Best wishes,
Hans

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

Re: Opening query(s)

Post by bknight »

HansV wrote:
08 Apr 2023, 13:13
1) Click the big Office button, then click the Access Options button at the bottom.
Select Current Database.
Scroll down to the Navigation section.
Clear the check box Display Navigation Pane.
Click OK.

The database will now open with the navigation pane hidden.
Press F11 to unhide it.

2) Use code like

DoCmd.OpenForm FormName:="frmTDAmeritradeExDates", View:=acFormDS
Forms("frmTDAmeritradeExDates").Move Left:=400, Top:=300

No idea how to position a query.
I viewed the property sheet of one of the forms and that had many more options than does the queries property sheet. The only items that had "relevance" was Grid X= 24 and Grid Y=24, but those values were on all forms, not on queries. There must be some hidden properties deep down, because each database that I have "remembers" where a particular form or query position was the last time a form or query was it was closed, as it opens where it existed the last time. The center property was set to no. I'll experiment and see what I learn.
Thanks

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

Re: Opening query(s)

Post by bknight »

HansV wrote:
08 Apr 2023, 13:13


The database will now open with the navigation pane hidden.
Press F11 to unhide it.
I should be careful of what I ask. What I really intended was to open with the navigation pane collapsed.

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

Re: Opening query(s)

Post by HansV »

You can use the following code in the On Load event of the startup form to minimize (collapse) the navigation pane:

Code: Select all

    DoCmd.SelectObject acModule, , True
    DoCmd.Minimize
Best wishes,
Hans

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

Re: Opening query(s)

Post by bknight »

I received an error: object required

Code: Select all

    DoCmd.SelectObject acModule, , True
    DoCmd.Minimize

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

Re: Opening query(s)

Post by HansV »

How about

Code: Select all

    DoCmd.SelectObject acTable, , True
    DoCmd.Minimize
If that doesn't work either, I cannot help you.
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 550
Joined: 27 Jun 2021, 10:46

Re: Opening query(s)

Post by SpeakEasy »

> "remembers" where a particular ... query position was

Are you quite sure? Queries have never been directly positionable, as far as I am aware. The normal 'trick' is to create a form based on the query, and set to Datasheet view

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

Re: Opening query(s)

Post by bknight »

I'm not quite sure what you're asking of me. Am I sure that the queries open where they were in the last session? Yes, I'm sure

Code: Select all

Private Sub Form_Load()
    Me.Recordset.MoveLast
    Me.[Tradedate].SetFocus
    DoCmd.OpenForm FormName:="frmProfit", View:=acNormal
    DoCmd.OpenForm FormName:="frmAction", View:=acFormDS
    Me.Profit.Locked = False
    DoCmd.OpenQuery "quDailyP/L"
    DoCmd.OpenQuery "quP/L"
    'DoCmd.SelectObject acModule, , True
    DoCmd.Minimize
End Sub
This is code attached to the form that opens when the Db is opened. The queries are where they were, the forms are where they were positioned.

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

Re: Opening query(s)

Post by bknight »

HansV wrote:
12 Apr 2023, 09:21
How about

Code: Select all

    DoCmd.SelectObject acTable, , True
    DoCmd.Minimize
If that doesn't work either, I cannot help you.
Changed to the above and seemed to work.