Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

New Query in VBA

Posted on 2004-04-17
5
Medium Priority
?
316 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
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
BillPowell earned 320 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

782 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