|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
The quickest way would be to save the sql as a query, then open that in code as follows:
docmd.openquery "QueryName" |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
Thanks a million Iwells
This is exactly what I needed to create a query on the fly. Works like a dream. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Best way to display VBA query results? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|