Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 22nd, 2004, 03:08 AM
BBJo BBJo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 21 BBJo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 & Chr(34) & ";"
 
Set rs = dbs.OpenRecordset(strSql, dbOpenSnapshot)
 
 


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

Many thanks

Reply With Quote
  #2  
Old December 22nd, 2004, 09:36 AM
sherrington sherrington is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 110 sherrington User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 30 m 33 sec
Reputation Power: 11
The quickest way would be to save the sql as a query, then open that in code as follows:

docmd.openquery "QueryName"

Reply With Quote
  #3  
Old December 22nd, 2004, 09:51 AM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 11
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

Reply With Quote
  #4  
Old December 22nd, 2004, 10:23 AM
BBJo BBJo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 21 BBJo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #5  
Old December 2nd, 2008, 08:16 AM
tekmeat tekmeat is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2008
Posts: 1 tekmeat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 5 sec
Reputation Power: 0
Works great

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

Reply With Quote
Reply

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


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

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