display query with code

R

Rudy

Tim,

you could try this function:

Public Sub ShowQuery(varSQL As Variant)
Dim dbsMyDatabase As Database 'DAO
Dim qryMyQueryDef As QueryDef

On Error GoTo Err_ShowQuery

Set dbsMyDatabase = CurrentDb
Set qryMyQueryDef = dbsMyDatabase.CreateQueryDef
("qryMyQuery")
qryMyQueryDef.SQL = varSQL
DoCmd.OpenQuery "qryMyQuery"
dbsMyDatabase.QueryDefs.Delete "qryMyQuery"

Exit_ShowQuery:
Exit Sub

Err_ShowQuery:
Select Case Err.Number
Case 3012 'Object already exists
Set qryMyQueryDef = dbsMyDatabase.QueryDefs
("qryMyQuery")
Resume Next
Case Else
MsgBox Err.Number & " - " & Err.Description,
vbExclamation, "ShowQuery"
Resume Exit_ShowQuery
End Select
End Sub


Good luck...

R.W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top