There sure is and it can be done by using code, qrydefs, or even Recordsets.
1. Using DoCmd.RunSQL
(Note: Open your query in SQL view, copy it, and paste it at strSQL =
"________". You can use the line continueation characters " & _ as shown
below. If it doesn't work try removing the ; at the end of the SQL)
Here is an example from one of my databases:
Dim strSQL As String
strSQL = "SELECT * FROM tblSSAttendance WHERE [txtSSClassDate] = '" & _
SSClassDate & "';"
DoCmd.RunSQL strSQL
2. OR by using a Recordset:
Private Sub cmdNewMinSalary_Click()
Dim rstEmployees As ADODB.Recordset
Dim strSQL As String
Set conDatabase = CurrentProject.Connection
strSQL = "SELECT * FROM Employees WHERE Salary < " & txtNewMinSalary
Set rstEmployees = New ADODB.Recordset
rstEmployees.Open strSQL, conDatabase, adOpenDynamic, adLockOptimistic
With rstEmployees
Do While Not .EOF
!Salary = txtNewMinSalary
.Update
.MoveNext
Loop
End With
MsgBox "The minimum salary of all employees has been set to " &
txtNewMinSalary
Me.txtNewMinSalary = Null 'My code
rstEmployees.Close
conDatabase.Close
Set rstEmployees = Nothing
Set conDatabase = Nothing
End Sub
(I would love to give credit for this sample which is from a website, but I
have forgotten which site it is.)
3. Or you can Google QueryDef and get instructions how to use that method.
Hunter57
Just huntin' for some data.
http://churchmanagementsoftware.googlepages.com