switch focus to query through VBA

J

jpm

Hi,

Version: Access 2k3
Creating a form to centralize some commands and pre-defined queries.
Click on button which triggers [Click] event within which call is made:
doCmd.OpenQuery "QueryX", acViewNormal, acReadOnly

Problem is the form retains focus and there seems to be no way to set the
focus on the query(datasheet view). Clicking on the query window results in
no response.
Is there a way to programmatically switch the focus to the query
results(data sheet view) where the data sheet is set to read only?
n.b. the main window in MS Access is minimized in AutoExec macro. The
AutoExec macro also calls the form that is preventing interaction with the
datasheet window once I've opened it (docmd.OpenQuery) This is because I've
set the form load mode to 'Dialog'.
So, while that prevents the user from interacting with the main database
window, it also prevents access to any other window.

Therefore the real question might be. How do I prevent access to particular
windows(e.g. the main database window) while permitting access to other
default UI's like a query's window in datasheet mode?

Any substantive pionters are appreciated.

JimM
 
S

Steve Schapel

Jim,

I think it is generally not a good idea to view a query datasheet. I
think the DoCmd.OpenQuery method should generally be restricted to
action queries (e.g. append, update, etc). You would be better to make
a form based on your QueryX query, and open that form instead. This
will give you more options for control of the interface.

As for the Database Window, this can be hidden from the user via the
Tools|Startup menu.
 
J

jpm

Thanks.

I realize that the proper UI is what you suggest. I was just trying to go
for a quasi interface, since this is only a temporary tool for a couple of
persons.


Steve Schapel said:
Jim,

I think it is generally not a good idea to view a query datasheet. I
think the DoCmd.OpenQuery method should generally be restricted to action
queries (e.g. append, update, etc). You would be better to make a form
based on your QueryX query, and open that form instead. This will give
you more options for control of the interface.

As for the Database Window, this can be hidden from the user via the
Tools|Startup menu.

--
Steve Schapel, Microsoft Access MVP
Hi,

Version: Access 2k3
Creating a form to centralize some commands and pre-defined queries.
Click on button which triggers [Click] event within which call is made:
doCmd.OpenQuery "QueryX", acViewNormal, acReadOnly

Problem is the form retains focus and there seems to be no way to set the
focus on the query(datasheet view). Clicking on the query window results
in no response.
Is there a way to programmatically switch the focus to the query
results(data sheet view) where the data sheet is set to read only?
n.b. the main window in MS Access is minimized in AutoExec macro. The
AutoExec macro also calls the form that is preventing interaction with
the datasheet window once I've opened it (docmd.OpenQuery) This is
because I've set the form load mode to 'Dialog'.
So, while that prevents the user from interacting with the main database
window, it also prevents access to any other window.

Therefore the real question might be. How do I prevent access to
particular windows(e.g. the main database window) while permitting access
to other default UI's like a query's window in datasheet mode?

Any substantive pionters are appreciated.

JimM
 
K

Klatuu

I would go a bit further and say it should not be used at all. For action
queries, I much prefer the CurrentDb.Execute statement. It is much faster
and doesn't trigger SetWarning messages.

That is because it is pure Jet. It bypasses the Access UI and goes directly
to Jet. It also works well with VBA constructed SQL statments.

Steve Schapel said:
Jim,

I think it is generally not a good idea to view a query datasheet. I
think the DoCmd.OpenQuery method should generally be restricted to action
queries (e.g. append, update, etc). You would be better to make a form
based on your QueryX query, and open that form instead. This will give
you more options for control of the interface.

As for the Database Window, this can be hidden from the user via the
Tools|Startup menu.

--
Steve Schapel, Microsoft Access MVP
Hi,

Version: Access 2k3
Creating a form to centralize some commands and pre-defined queries.
Click on button which triggers [Click] event within which call is made:
doCmd.OpenQuery "QueryX", acViewNormal, acReadOnly

Problem is the form retains focus and there seems to be no way to set the
focus on the query(datasheet view). Clicking on the query window results
in no response.
Is there a way to programmatically switch the focus to the query
results(data sheet view) where the data sheet is set to read only?
n.b. the main window in MS Access is minimized in AutoExec macro. The
AutoExec macro also calls the form that is preventing interaction with
the datasheet window once I've opened it (docmd.OpenQuery) This is
because I've set the form load mode to 'Dialog'.
So, while that prevents the user from interacting with the main database
window, it also prevents access to any other window.

Therefore the real question might be. How do I prevent access to
particular windows(e.g. the main database window) while permitting access
to other default UI's like a query's window in datasheet mode?

Any substantive pionters are appreciated.

JimM
 

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