MLH <CRCI@NorthState.net> wrote:[color=blue]
> Also, if I remove the square brackets from the Period fieldname in the
> SQL statement, the error is different and occurs on a different
> line...
>
> Private Sub Command1_Click()
> Dim MyWS As Workspace
> Set MyWS = DBEngine.Workspaces(0)
> Dim MyDB As Database
> Dim MyQD As QueryDef, MyRecSet As Recordset
> Dim MyPeriod As String, MyRand As Double
> Set MyDB = MyWS.Databases(0)
> ' Set MyQD = MyDB.CreateQueryDef("SELECT [Period] FROM tblJobsites
> WHERE [Period]='M';")
> Set MyQD = MyDB.CreateQueryDef("SELECT Period FROM tblJobsites
> WHERE Period='M';")
>
> With MyQD
> ' Create temporary QueryDef.
> ' .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M';"
> Set MyRecSet = .OpenRecordset 'This line gave me prob -
> Access said it couldn't find tblJobsites. Why?
> MyRecSet.MoveFirst
> End With
>
>
> Runtime error 3067...
> Query input must contain at least one table or query.
>
> Debug reports this as the problematic line...
> Set MyRecSet = .OpenRecordset[/color]
Did you bother to check the Access help? A quick look showed your syntax
problem.. you need to specifiy an empty string as the QueryDef name.
This should work...
Dim MyWS As Workspace
Set MyWS = DBEngine.Workspaces(0)
Dim MyDB As Database
Dim MyQD As QueryDef, MyRecSet As Recordset
Dim MyPeriod As String, MyRand As Double
Set MyDB = MyWS.Databases(0)
Set MyQD = MyDB .CreateQueryDef("")
With MyQD
.SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M'"
Set MyRecSet = .OpenRecordset()
MyRecSet.MoveFirst
End With
OR
Dim MyWS As Workspace
Set MyWS = DBEngine.Workspaces(0)
Dim MyDB As Database
Dim MyQD As QueryDef, MyRecSet As Recordset
Dim MyPeriod As String, MyRand As Double
Set MyDB = MyWS.Databases(0)
Set MyQD = MyDB .CreateQueryDef("", SELECT [Period] FROM tblJobsites
WHERE [Period]='M')
With MyQD
Set MyRecSet = .OpenRecordset()
MyRecSet.MoveFirst
End With
--
regards,
Bradley
A Christian Response
http://www.pastornet.net.au/response