You are on page 1of 3

Tutorials: - Select - Resources: - Select - Forums: - Select -

Microsoft Access Development


Forums: Register | User CP | Games | Calendar | Members | FAQs | Sitemap | Support |

User Name:
User Name
Password:
Log in

Remember me

Dev Articles Community Forums > Databases > Microsoft Access Development
Best way to display VBA query results?
Discuss Best way to display VBA query results? in the Microsoft Access Development forum on Dev Articles.
Best way to display VBA query results? Microsoft Access Development forum to discuss problems and solutions with this popular DBMS. Use
Access to build and modify database tables, or full-featured applications.

AddThisThreadTo: Del.icio.us Digg Google Spurl Blink Furl Simpy Y! MyWeb

Previous Thread | Next Thread Thread Tools Search this Thread Display Modes

DevArticlesCommunityForumsSponsor:

December22nd,2004,03:08AM #1

BBJo Join Date: Dec 2004


Posts: 21
Registered User Time spent in forums: 5 h 10 m 15 sec
Reputation Power: 0

Best way to display VBA query results?

What is the best way to display the results from a VBA query in Access (97)?

User fires of query with a button click. I just want to open up a table view of the results but since I am new to
Access dev I am not sure how to do this.

Code is:

Code:

Dim productName As String


Dim strSql As String
Dim dbs As Database
Set dbs = CurrentDb()
Dim rs As Recordset

productName = "ADSL"

strSql = "SELECT [Information].* From [Information] WHERE [Information].Product = " & Chr(34) & productName &

Set rs = dbs.OpenRecordset(strSql, dbOpenSnapshot)

How do I open the RecordSet up in a table (view)?

Many thanks
December22nd,2004,09:36AM #2

sherrington Join Date: Aug 2004


Posts: 110
Contributing User Time spent in forums: 13 h 30 m 33 sec
Reputation Power: 13

The quickest way would be to save the sql as a query, then open that in code as follows:

docmd.openquery "QueryName"

December22nd,2004,09:51AM #3

lwells Join Date: Sep 2004


Posts: 632
Contributing User Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 13

To view the record set you need to create a temporary query to view and then delete the temp query when
finished. Use the following code to create a temporary query that is named tmpProductInfo

Dim dbs As Database


Dim rs As Recordset
Dim qdf As QueryDef
Dim productName As String
Dim strSql As String

Set dbs = CurrentDb()

productName = "ADSL"

strSql = "SELECT [Information].* From [Information] WHERE [Information].Product = " & Chr(34) &
productName & Chr(34) & ";"

Set rs = dbs.OpenRecordset(strSql, dbOpenSnapshot)

With dbs
Set qdf = .CreateQueryDef("tmpProductInfo", strSql)
DoCmd.OpenQuery "tmpProductInfo"
.QueryDefs.Delete "tmpProductInfo"
End With
dbs.Close
qdf.Close

lwells

December22nd,2004,10:23AM #4

BBJo Join Date: Dec 2004


Posts: 21
Registered User Time spent in forums: 5 h 10 m 15 sec
Reputation Power: 0

Thanks a million Iwells

This is exactly what I needed to create a query on the fly.

Works like a dream.

December2nd,2008,08:16AM #5
tekmeat Join Date: Dec 2008
Posts: 1
Registered User
Time spent in forums: 13 m 5 sec
Reputation Power: 0

Works great

I used this as well. It worked perfectly. thank you.

Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Best way
to display VBA query results?

Previous Thread | Next Thread

Developer Shed Advertisers and Affiliates

Thread Tools Search this Thread

Email this Page Search this Thread:


Go
Advanced Search

Display Modes Rate This Thread

Linear Mode Rate This Thread:


Switch to Hybrid Mode 5 : Excellent Go
Switch to Threaded Mode

Posting Rules

You may not post new threads


You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
[IMG] code is On Forum Jump
HTML code is Off Microsoft Access Development Go

Forums: Register | User CP | Games | Calendar | Members | FAQs | Sitemap | Support |

Powered by: vBulletin Version 3.0.5


Copyright 2000 - 2017, Jelsoft Enterprises Ltd.

2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap

You might also like