The commands "DoCmd.RunSQL " and "CurrentDB.Execute" only work with Action queries.
"DoCmd.OpenQuery" only works with saved queries (a valid name of a query in the current database). It will open a Select query or execute Action queries.
---------------------------------------------------------------------------------
Using VBA, you would use something like:
Code:
Public Sub test()
Dim d As DAO.Database
Dim r As DAO.Recordset
Dim strQue As String
Set d = CurrentDb
strQue = "SELECT tblProposalWorksheet.fLngProposalNo " _
& "FROM tblProposalWorksheet " _
& "WHERE (((tblProposalWorksheet.fLngProposalNo)=1993074)); "
Set r = d.OpenRecordset(strQue)
If Not (r.BOF And r.EOF) Then
'Do something
End If
r.Close
Set r = Nothing
Set d = Nothing
End Sub
------------------------------------------------------------
Create a query, switch to SQL view and paste in:
Code:
SELECT tblProposalWorksheet.fLngProposalNo
FROM tblProposalWorksheet
WHERE (((tblProposalWorksheet.fLngProposalNo)=1993074));
Save the query as "Query3".
Then run this code:
Code:
Public Sub test2()
Dim strQue As String
strQue = "Query3"
DoCmd.OpenQuery (strQue)
End Sub
The query opens and is visible..... You can add new data and do edits, but not very useful (IMO - no control on how data is entered - no validation). Using a form & filter the record source would be much better....
My $0.02