michaelc80
New member
- Local time
- Today, 04:16
- Joined
- Oct 19, 2006
- Messages
- 7
All,
Some time ago I posted a question and received assistance (many thanks). However I need to tweak the code some. Here is what I have.
Private Sub btnGetErr_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
strSQL = "SELECT SQL FROM DATA_SCRUB_SQL " &_
"WHERE Error_ID = Forms!frmErrors!txtErrorNumber;"
Set db = CurrentDb
Set qdf = db.QueryDefs("qryResults")
qdf.SQL = strSQL
DoCmd.OpenQuery "qryResults", acViewNormal, acReadOnly
Set qdf = Nothing
Set db = Nothing
End Sub
What the above code does is retrieve a SQL string listed in the field SQL of the table DATA_SCRUB_SQL and return the SQL string in a query called "qryResults". It's selects the one that is associated with the field Error_ID, which is input by the user in a text box.
However, what I'd like it to do is actually run the SQL string that is in the SQL field, and return the results. For example, if the SQL code is "Select * from tablename" I'd like it to run that and return the results. It currently just shows the SQL code in the query.
Any help is appreciated!
Some time ago I posted a question and received assistance (many thanks). However I need to tweak the code some. Here is what I have.
Private Sub btnGetErr_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
strSQL = "SELECT SQL FROM DATA_SCRUB_SQL " &_
"WHERE Error_ID = Forms!frmErrors!txtErrorNumber;"
Set db = CurrentDb
Set qdf = db.QueryDefs("qryResults")
qdf.SQL = strSQL
DoCmd.OpenQuery "qryResults", acViewNormal, acReadOnly
Set qdf = Nothing
Set db = Nothing
End Sub
What the above code does is retrieve a SQL string listed in the field SQL of the table DATA_SCRUB_SQL and return the SQL string in a query called "qryResults". It's selects the one that is associated with the field Error_ID, which is input by the user in a text box.
However, what I'd like it to do is actually run the SQL string that is in the SQL field, and return the results. For example, if the SQL code is "Select * from tablename" I'd like it to run that and return the results. It currently just shows the SQL code in the query.
Any help is appreciated!