New Query default to SQL View

C

Chuck

When creating a new Query in Access, how do you go about making the new query
window default to the "SQL View" rather than the "Design View"? I almost
never use the "Design View" anyway.

Regards,

chuck t.
 
6

'69 Camaro

Hi, Chuck.
how do you go about making the new query
window default to the "SQL View" rather than the "Design View"?

There's no setting to change the default view. You're stuck with it unless
you want to do some leg work. Create a new button on your (Custom or
Database) CommandBar with the following Properties:

Caption: New Query
Screen Tip: New Query
On Action =openNewQry()

Then paste the following code into a new module:

' * * * * Start Code * * * *

Public Function openNewQry()

On Error GoTo ErrHandler

SendKeys "~", False
RunCommand acCmdNewObjectQuery
RunCommand acCmdSQLView

Exit Function

ErrHandler:

MsgBox "Error in openNewQry( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Function

' * * * * End Code * * * *

Save the module and name it anything exept openNewQry. Compile the code and
anytime you need to create a new query defaulting to the SQL View pane, just
select this new CommandBar button to open the "Show Tables" dialog window,
select your tables and queries in the list box, then select the "Close"
button. The SQL View pane will pop up with a SELECT keyword followed by the
FROM clause including the tables and queries you selected.

The downside is that this code doesn't exist in every database file, so any
database file that you'd like to use this new feature in will require an
import of this new module and, if you used a custom CommandBar for this
button instead of a built-in CommandBar, the custom CommandBar, too. After
import, the code in the database must be compiled.

But any time you want to open a new query in Design View instead of SQL
View, just use the method that you previously used. At least now you have
choice.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are [email protected] and [email protected]

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that questions
answered the quickest are often from those who have a history of rewarding
the contributors who have taken the time to answer questions correctly.
 
C

Chaim

Someone asked that question just the other day. The answer was that there is
no way to make SQL View the default view. You have to go through the
exercise of opening the query in Design View, switch to SQL View, and then
save your query in SQL View. The next time you open the query, it will open
in SQL View.
 
C

Chuck

Ah, very good 69 Camaro! What I REALLY like is that when I have a table
selected Access knows enough to automatically include the name of that table
in my sql.

What would make the trick permanent would be to build your solution as an
Add-In. Any takers?
 
6

'69 Camaro

Hi, Chuck.
What I REALLY like is that when I have a table
selected Access knows enough to automatically include the name of that
table
in my sql.

That's one of the side benefits. It also works for any query selected in
the Database Window.
What would make the trick permanent would be to build your solution as an
Add-In.

Personally, I have a library database full of utilities that I set a
Reference to for any new databases, so I never import this code. I've found
that the Access community tends to ignore library databases and custom
classes, so these are things that I don't offer as recommendations any more.
But since you know that custom Add-ins can be created, you might be more
open to the idea of library databases, too. If you go this route, you'll
have to remember to remove the Reference and recompile the code when
deploying the application to others, because they won't have the same
library file in the same path on their computers.

This code could easily be used to create a custom Add-in, but if it were me,
I'd want a lot more functionality out of an Add-in than just a single
CommandBar button.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are [email protected] and [email protected]
 
Top