I have a database project written by someone else that uses a large number of SQL strings that are constructed on the basis of a series of elaborate IF/THEN or CASE/ELSE decision trees.
In order to understand what is going on I capture the SQL and turn it into a tmporary querydef and then use doCMD.Openquery to see the data sheet.
My code looks like this
Dim dbs as Database
Dim qdf as Querydef
Dim StrSQL as String
stSQLr = "SELECT someData FROM someTable"
dbs.createQueryDef("tmpInfo", strSQL)
DoCmd.OpenQuery "tmpInfo"
Response = msgbox("Close tmpInfo sheet?", vbYesNo)
If Response = 6 then
DoCmd.Cose aCQuery, "tmpInfo"
dbs.QueryDefs. Delete "tmpInfo"
qdf.Close
dbs.Close
End If
And this works fine for the first four or five sets of strSQLs.
Then I come to one strSQL that returns one record from one field.
In this case the code runs and does not throw an error, but the data sheet does not appear.
However if I exit the Debug mode and go back to the current form, the tmpInfo query exists and if I execute it manually from the object explorer, then it displays as expected.
I also created a form with a listbox on it, with the datasource set to the queryDef "tmpInfo"
On Load, the form sets the number of columns in the lstbox equal to the field count for the querydef "tmpInfo".
This form also works and also exhibits the same behavior: when called for that particular "tmpInfo" query it does not throw an error, but nothing happens.
However, if I exit the Debug mode and display the form manually, then it works as expected.
What is preventing DoCmd.OpenQuery "tmpInfo" or DoCmd.Openform "tmpInfo" from working from code when they will work manually?