467,894 Members | 1,469 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

Database engine cannot find table. Why not?

MLH
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)

Nov 13 '05 #1
  • viewed: 13891
Share:
17 Replies
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" <CR**@NorthState.net> wrote in message
news:o7********************************@4ax.com...
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)

Nov 13 '05 #2
Br
MLH <CR**@NorthState.net> wrote:
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'"
^^^

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

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)


--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #3

"Br@dley" <n0****@4u.com> wrote in message
news:OV************@news-server.bigpond.net.au...
MLH <CR**@NorthState.net> wrote:
Have you forgotten the ; character at the end of your SQL statement???


The semicolon isn't required.

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


Nov 13 '05 #4
MLH
Its a fair Q. Yes, it has 604 records in it.
I backed it up in the same dbase ==>
tblJobsitesBAKUP.
Nov 13 '05 #5
MLH
Have tried both with and without the semicolon.
Same err rtnd either way.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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

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)


Nov 13 '05 #6
MLH
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.
Nov 13 '05 #7
MLH
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.
Nov 13 '05 #8
MLH
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
Nov 13 '05 #9
MLH
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.
Nov 13 '05 #10

"MLH" <CR**@NorthState.net> wrote in message
news:nh********************************@4ax.com...
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.


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

Nov 13 '05 #11
MLH
>Run-time error 3012...
Object "SELECT Period FROM tblJobsites WHERE Period="M';" already
exists.


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.
Nov 13 '05 #12
Br
MLH <CR**@NorthState.net> wrote:
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


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
Nov 13 '05 #13
Br
MLH <CR**@NorthState.net> wrote:
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.


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
Nov 13 '05 #14
MLH
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"
<No****@Not.This.Address> wrote:
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.


Nov 13 '05 #15
Br
MLH <CR**@NorthState.net> wrote:
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.
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

On Wed, 25 May 2005 12:23:54 +1200, "Jeff Smith"
<No****@Not.This.Address> wrote:
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.


--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #16
MLH
You were right. Many thanks.
Nov 13 '05 #17
MLH <CR**@NorthState.net> wrote in
news:o7********************************@4ax.com:
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)


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
Nov 13 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by dskillingstad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.