Hi, Blake.
Instead of .openquery("Name of query") is there a function that will allow me
to call a SQL command using the actual SQL command string (SELECT * ....)?
Without knowing how this SQL statement is going to be used, one can only be
vague on its uses. One may use a SQL statement for a Recordset Object, a
QueryDef Object, a Row Source Property of a combo box or list box, or with
the Execute method (for action queries only).
Or is there a way to modify a prebuilt query from the form code?
Absolutely. Here's an example of an existing query named qryTemp being
modified in VBA code:
Public Sub TransferTextWParam(sDataSrc As String, sFldName As String,
sCriteria As String)
On Error GoTo ErrHandler
Dim qry As QueryDef
Dim sqlStmt As String
sqlStmt = "SELECT * " & _
"FROM " & sDataSrc & _
" WHERE (" & sFldName & " = '" & sCriteria & "');"
Set qry = CurrentDb().QueryDefs("qryTemp")
qry.SQL = sqlStmt
DoCmd.TransferText acExportDelim, , qry.Name, "C:\Data\XferText.txt", True
CleanUp:
Set qry = Nothing
Exit Sub
ErrHandler:
MsgBox "Error in TransferTextWParam( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
GoTo CleanUp
End Sub
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.