Solved

New Query in VBA

Posted on 2004-04-17
5
301 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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

624 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