C
CJ
I have a form that is used to generate dynamic SQL. On
the form is a command button that - upon click - will
produce a query based upon the variables input into the
form. It prompts for a name for this query, then saves
it, but does not open the query for viewing.
Any idea how I might get it to do so (also open the
query)? Thanks in advance.
CJ
Here's the code that generates the query:
Private Sub cmdCreateQDF_Click()
On Error GoTo ErrHandler
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strName As String
strName = Application.Run
("acwzmain.wlib_stUniquedocname", "Query1", acQuery)
strName = InputBox("Please specify a query
name", "Save As", strName)
If Not strName = vbNullString Then
Set db = CurrentDb
Set qdf = db.CreateQueryDef(strName, Me.txtSQL)
qdf.Close
Else
MsgBox "The save operation was cancelled." & vbCrLf
& _
"Please try again.", vbExclamation +
vbOKOnly, "Cancelled"
End If
ExitHere:
On Error Resume Next
qdf.Close
Set qdf = Nothing
db.QueryDefs.Refresh
Set db = Nothing
Exit Sub
ErrHandler:
Resume ExitHere
End Sub
the form is a command button that - upon click - will
produce a query based upon the variables input into the
form. It prompts for a name for this query, then saves
it, but does not open the query for viewing.
Any idea how I might get it to do so (also open the
query)? Thanks in advance.
CJ
Here's the code that generates the query:
Private Sub cmdCreateQDF_Click()
On Error GoTo ErrHandler
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strName As String
strName = Application.Run
("acwzmain.wlib_stUniquedocname", "Query1", acQuery)
strName = InputBox("Please specify a query
name", "Save As", strName)
If Not strName = vbNullString Then
Set db = CurrentDb
Set qdf = db.CreateQueryDef(strName, Me.txtSQL)
qdf.Close
Else
MsgBox "The save operation was cancelled." & vbCrLf
& _
"Please try again.", vbExclamation +
vbOKOnly, "Cancelled"
End If
ExitHere:
On Error Resume Next
qdf.Close
Set qdf = Nothing
db.QueryDefs.Refresh
Set db = Nothing
Exit Sub
ErrHandler:
Resume ExitHere
End Sub