Solved

New Query in VBA

Posted on 2004-04-17
5
295 Views
Last Modified: 2008-03-06
I'm just wanting to know if there is a way to open a new query or report from vba.  So if a user clicks an add new query button, it opens a new query window.  It would be even better if the add new tables dialog was open as well.

Thanks
Drizzt
0
Comment
Question by:Drizzt95
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
BillPowell earned 80 total points
ID: 10851824
Hi Drizzt,

Heres on way to do it.

1. Create a textbox on your form for users to type in the name of the query they will create.
2. In the onclick event for the command button:

Private Sub cmdQuery_Click()
    CurrentDb.CreateQueryDef Me.txtQueryName
    DoCmd.OpenQuery Me.txtQueryName, acViewDesign
    DoCmd.RunCommand acCmdShowTable
End Sub


This creates a querydef in your database with the name from the textbox and then has it open up with the blank query with the tables dialog so they can begin their query.

Bill
0
 
LVL 3

Author Comment

by:Drizzt95
ID: 10852726
That works great, what about adding a report?
0
 
LVL 11

Expert Comment

by:BillPowell
ID: 10853709
Here ya go.  Somewhat different than the query.  No name required in the textbox, just creates the blank report.  When you go to close it, it will prompt you for a name.

Private Sub cmdReport_Click()
    Dim rpt As Report
    Set rpt = CreateReport
    DoCmd.Restore
End Sub
0
 
LVL 3

Author Comment

by:Drizzt95
ID: 10855436
Thanks for your help.  I looked everywhere on the net but couldn't find an answer to the report part.
I'll throw in a few extra points for answering a two part question.

Thanks again
Drizzt
0
 
LVL 11

Expert Comment

by:BillPowell
ID: 10855766
No problem, glad it worked out :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question