Connecting Tech Pros Worldwide Help | Site Map

Database engine cannot find table. Why not?

MLH
Guest
 
Posts: n/a
#1: Nov 13 '05
The Microsoft Jt database engine can not find
tblJobSites, error #3078. That's what I get when
executing this code...

Private Sub Command1_Click()
Dim MyWorkspace As Workspace
Set MyWorkspace = DBEngine.Workspaces(0)
Dim MyDB As Database
Dim MyQueryDef As QueryDef, MyRecSet As Recordset
Dim MyPeriod As String, MyRand As Double
Set MyDB = MyWorkspace.Databases(0)
Set MyQueryDef = MyDB.CreateQueryDef("")

With MyQueryDef
' Create temporary QueryDef.
.SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M'"
Set MyRecSet = .OpenRecordset()
MyRecSet.MoveFirst
End With

Debug reports the problematic line ...
Set MyRecSet = .OpenRecordset()

What have I done wrong here?

(frmProgrammerOnly, Command1 button click, deadpest.mdb)

Douglas J. Steele
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Database engine cannot find table. Why not?


I hate to ask the obvious, but do you have a table named tblJobsites? Might
it actually be tblJobsite or some other variation?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"MLH" <CRCI@NorthState.net> wrote in message
news:o75791dbbco3pctlik3q0rb5qha7t1krmm@4ax.com...[color=blue]
> The Microsoft Jt database engine can not find
> tblJobSites, error #3078. That's what I get when
> executing this code...
>
> Private Sub Command1_Click()
> Dim MyWorkspace As Workspace
> Set MyWorkspace = DBEngine.Workspaces(0)
> Dim MyDB As Database
> Dim MyQueryDef As QueryDef, MyRecSet As Recordset
> Dim MyPeriod As String, MyRand As Double
> Set MyDB = MyWorkspace.Databases(0)
> Set MyQueryDef = MyDB.CreateQueryDef("")
>
> With MyQueryDef
> ' Create temporary QueryDef.
> .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M'"
> Set MyRecSet = .OpenRecordset()
> MyRecSet.MoveFirst
> End With
>
> Debug reports the problematic line ...
> Set MyRecSet = .OpenRecordset()
>
> What have I done wrong here?
>
> (frmProgrammerOnly, Command1 button click, deadpest.mdb)
>[/color]


Br@dley
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Database engine cannot find table. Why not?


MLH <CRCI@NorthState.net> wrote:[color=blue]
> The Microsoft Jt database engine can not find
> tblJobSites, error #3078. That's what I get when
> executing this code...
>
> Private Sub Command1_Click()
> Dim MyWorkspace As Workspace
> Set MyWorkspace = DBEngine.Workspaces(0)
> Dim MyDB As Database
> Dim MyQueryDef As QueryDef, MyRecSet As Recordset
> Dim MyPeriod As String, MyRand As Double
> Set MyDB = MyWorkspace.Databases(0)
> Set MyQueryDef = MyDB.CreateQueryDef("")
>
> With MyQueryDef
> ' Create temporary QueryDef.
> .SQL = "SELECT [Period] FROM tblJobsites WHERE [Period]='M'"[/color]

^^^

Have you forgotten the ; character at the end of your SQL statement???

[color=blue]
> Set MyRecSet = .OpenRecordset()
> MyRecSet.MoveFirst
> End With
>
> Debug reports the problematic line ...
> Set MyRecSet = .OpenRecordset()
>
> What have I done wrong here?
>
> (frmProgrammerOnly, Command1 button click, deadpest.mdb)[/color]

--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response


Douglas J. Steele
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Database engine cannot find table. Why not?



"Br@dley" <n0mail@4u.com> wrote in message
news:OVNke.38$BR4.6@news-server.bigpond.net.au...[color=blue]
> MLH <CRCI@NorthState.net> wrote:
> Have you forgotten the ; character at the end of your SQL statement???[/color]

The semicolon isn't required.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)




MLH
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Database engine cannot find table. Why not?


Its a fair Q. Yes, it has 604 records in it.
I backed it up in the same dbase ==>
tblJobsitesBAKUP.
MLH
Guest
 
Posts: n/a
#6: Nov 13 '05

re: Database engine cannot find table. Why not?


Have tried both with and without the semicolon.
Same err rtnd either way.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[color=blue]
>
>Have you forgotten the ; character at the end of your SQL statement???
>
>[color=green]
>> Set MyRecSet = .OpenRecordset()
>> MyRecSet.MoveFirst
>> End With
>>
>> Debug reports the problematic line ...
>> Set MyRecSet = .OpenRecordset()
>>
>> What have I done wrong here?
>>
>> (frmProgrammerOnly, Command1 button click, deadpest.mdb)[/color][/color]

MLH
Guest
 
Posts: n/a
#7: Nov 13 '05

re: Database engine cannot find table. Why not?


The precise error message...

Run-time error '3078':
The Microsoft Jet database engine cannot find the input table or query
'tblJobsites'. Make sure it exists and that its name is spelled
correctly.

I have copied the table to another table named 'a' and tried the same
code again. It reports not being able to find 'a' as well. I have
closed and reopened the database. Perhaps there's something
wrong with my code syntax. I would appreciate you checking.
MLH
Guest
 
Posts: n/a
#8: Nov 13 '05

re: Database engine cannot find table. Why not?


Notice if I slightly change the SQL assignment to this...
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';")

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

You see where I rem'd out the .SQL assignment in the With clause?
I put it in a few lines up - just before the With statement. Debog
reports the exact same error, citing that line as the problematic
line. How can the Set MyQD line fail??? I just don't understand.
MLH
Guest
 
Posts: n/a
#9: Nov 13 '05

re: Database engine cannot find table. Why not?


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
MLH
Guest
 
Posts: n/a
#10: Nov 13 '05

re: Database engine cannot find table. Why not?


I compacted the database to db1.mdb and repaired it
successfully. Then I opened db1 and ran this code again...

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


This time the error returned was different...
Run-time error 3012...
Object "SELECT Period FROM tblJobsites WHERE Period="M';" already
exists.

Am I not exiting the Workspace? What's going on. If I stop & restart
Access, this error is not the first, but you can bet it'll be the
second if I run the code again in the same instance of Access.
Jeff Smith
Guest
 
Posts: n/a
#11: Nov 13 '05

re: Database engine cannot find table. Why not?



"MLH" <CRCI@NorthState.net> wrote in message
news:nhf791t63rq4k568u12ltmubqbnthshkpg@4ax.com...[color=blue]
> Notice if I slightly change the SQL assignment to this...
> 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';")
>
> 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
>
> You see where I rem'd out the .SQL assignment in the With clause?
> I put it in a few lines up - just before the With statement. Debog
> reports the exact same error, citing that line as the problematic
> line. How can the Set MyQD line fail??? I just don't understand.[/color]

The first part of the CreateQueryDef method is the name of the query being
created. Try
Set MyQD = MyDB.CreateQueryDef("", "SELECT [Period] FROM tblJobsites WHERE
[Period]='M';") or

Set MyQD = MyDB.CreateQueryDef("TempQuery1", "SELECT [Period] FROM
tblJobsites WHERE [Period]='M';")
Remember this will add a new query under the queries collection in the
database window.

Also what are you trying to do with the newly created query? If you're just
going to loop through the records, try using a recordset instead.

Jeff



MLH
Guest
 
Posts: n/a
#12: Nov 13 '05

re: Database engine cannot find table. Why not?


>Run-time error 3012...[color=blue]
>Object "SELECT Period FROM tblJobsites WHERE Period="M';" already
>exists.[/color]

I am getting this error everytime I runt the code now. Even when
I reboot the PC, launch Access 97, open the database and run
the code for the first time in the new instance of Access.
Br@dley
Guest
 
Posts: n/a
#13: Nov 13 '05

re: Database engine cannot find table. Why not?


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


Br@dley
Guest
 
Posts: n/a
#14: Nov 13 '05

re: Database engine cannot find table. Why not?


MLH <CRCI@NorthState.net> wrote:[color=blue]
> I compacted the database to db1.mdb and repaired it
> successfully. Then I opened db1 and ran this code again...
>
> 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
>
>
> This time the error returned was different...
> Run-time error 3012...
> Object "SELECT Period FROM tblJobsites WHERE Period="M';" already
> exists.
>
> Am I not exiting the Workspace? What's going on. If I stop & restart
> Access, this error is not the first, but you can bet it'll be the
> second if I run the code again in the same instance of Access.[/color]

Look under your Queries list... I suspect you've created a query named
"SELECT Period FROM tblJobsites WHERE Period="M';" !!!???

See my previous post.
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response


MLH
Guest
 
Posts: n/a
#15: Nov 13 '05

re: Database engine cannot find table. Why not?


Thanks Jeff. I have a hunch this'll work. BTW, all I'm gonna do is
loop through the records. I thought I needed to have a querydef
for that in DAO.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Wed, 25 May 2005 12:23:54 +1200, "Jeff Smith"
<NoSpam@Not.This.Address> wrote:
[color=blue]
>Try
>Set MyQD = MyDB.CreateQueryDef("", "SELECT [Period] FROM tblJobsites WHERE
>[Period]='M';") or
>
>Set MyQD = MyDB.CreateQueryDef("TempQuery1", "SELECT [Period] FROM
>tblJobsites WHERE [Period]='M';")
>Remember this will add a new query under the queries collection in the
>database window.
>
>Also what are you trying to do with the newly created query? If you're just
>going to loop through the records, try using a recordset instead.[/color]

Br@dley
Guest
 
Posts: n/a
#16: Nov 13 '05

re: Database engine cannot find table. Why not?


MLH <CRCI@NorthState.net> wrote:[color=blue]
> Thanks Jeff. I have a hunch this'll work. BTW, all I'm gonna do is
> loop through the records. I thought I needed to have a querydef
> for that in DAO.[/color]

Nope..

Just do something like....

mySQL = "SELECT [Period] FROM tblJobsitesWHERE [Period]='M';"
Set myRS = CurrentDB.OpenRecordset(mySQL, dbOpenDynaset)
myRS.MoveFirst
Do Until myRS.EOF
'code
myRS.MoveNext
Loop

[color=blue]
> On Wed, 25 May 2005 12:23:54 +1200, "Jeff Smith"
> <NoSpam@Not.This.Address> wrote:
>[color=green]
>> Try
>> Set MyQD = MyDB.CreateQueryDef("", "SELECT [Period] FROM tblJobsites
>> WHERE [Period]='M';") or
>>
>> Set MyQD = MyDB.CreateQueryDef("TempQuery1", "SELECT [Period] FROM
>> tblJobsites WHERE [Period]='M';")
>> Remember this will add a new query under the queries collection in
>> the database window.
>>
>> Also what are you trying to do with the newly created query? If
>> you're just going to loop through the records, try using a recordset
>> instead.[/color][/color]

--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response


MLH
Guest
 
Posts: n/a
#17: Nov 13 '05

re: Database engine cannot find table. Why not?


You were right. Many thanks.
David W. Fenton
Guest
 
Posts: n/a
#18: Nov 13 '05

re: Database engine cannot find table. Why not?


MLH <CRCI@NorthState.net> wrote in
news:o75791dbbco3pctlik3q0rb5qha7t1krmm@4ax.com:
[color=blue]
> The Microsoft Jt database engine can not find
> tblJobSites, error #3078. That's what I get when
> executing this code...
>
> Private Sub Command1_Click()
> Dim MyWorkspace As Workspace
> Set MyWorkspace = DBEngine.Workspaces(0)
> Dim MyDB As Database
> Dim MyQueryDef As QueryDef, MyRecSet As Recordset
> Dim MyPeriod As String, MyRand As Double
> Set MyDB = MyWorkspace.Databases(0)
> Set MyQueryDef = MyDB.CreateQueryDef("")
>
> With MyQueryDef
> ' Create temporary QueryDef.
> .SQL = "SELECT [Period] FROM tblJobsites WHERE
> [Period]='M'" Set MyRecSet = .OpenRecordset()
> MyRecSet.MoveFirst
> End With
>
> Debug reports the problematic line ...
> Set MyRecSet = .OpenRecordset()
>
> What have I done wrong here?
>
> (frmProgrammerOnly, Command1 button click, deadpest.mdb)[/color]

If you paste the SQL into the query designer's SQL view, does it
give you the same error?

I don't quite understand why you're using a querydef. Why not just
open a recordset with the SQL?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Closed Thread