Run-time Error 3078 - cannot find input table (1 Viewer)

twcaddell

Registered User.
Local time
Today, 06:09
Joined
Apr 8, 2013
Messages
31
I have a form that has a button that calls the following code:

Sub ClosePO_Click()
Dim db As DAO.Database
Dim mvalue As String, strSql as string

Set db = CurrentDb
mvalue = Me.Combo73 'combo box on OpenPO Form
strSql = "UPDATE Print SET OpenPO = NO where [GPO Invoice Number] = '" & mvalue & "'"
Debug.Print strSql
db.Execute dbFailOnError

db.Close
Set db = Nothing

End Sub

When I run (or step through the code, I get the Run-Time Error 3078 ... database cannot find the input table.

However, when I copy the debug.print output in the immmediate window and paste into the query builder, the query runs. Here is an example of the debug.print output:
UPDATE [Print] set OpenPO = NO where [GPO Invoice Number] = '40333'
where OpenPO is a yes/no field and [GPO Invoice Number] is a string

Really stuck on this one and would appreciate any help.

Thanks
TC
 

spikepl

Eledittingent Beliped
Local time
Today, 13:09
Joined
Nov 3, 2010
Messages
6,142
Here is a list of reserved words that you should not use to name objects, variables, functions or anything else in VBA/SQL: http://allenbrowne.com/AppIssueBadWord.html

I note that the debug.print output you show does NOT correspond to the VBA/SQL you show. SInce your debug.print works, and your original SQL doesn't, then what should be changed?
 

twcaddell

Registered User.
Local time
Today, 06:09
Joined
Apr 8, 2013
Messages
31
SpikePL
Thanks. I added the brackets around the Print table and still received the same error in the SQL statement. I had copied the wrong debug.print is why they were the same, but since Print is a reserve word, I thought I would put them back in. I will have to go through my code and change the name of the Print table --> probably PrintTbl

Still curious why the query builder runs the query but the code doesn't

Again thanks
TC
 

spikepl

Eledittingent Beliped
Local time
Today, 13:09
Joined
Nov 3, 2010
Messages
6,142
This is confusing now.

Show the exact code you have which generates the 3078 error when you run it AND the exact corresponding output of debug.print that runs without generating the error.
 

jdraw

Super Moderator
Staff member
Local time
Today, 07:09
Joined
Jan 23, 2006
Messages
15,393
From your post #1
...
Set db = CurrentDb
mvalue = Me.Combo73 'combo box on OpenPO Form
strSql = "UPDATE Print SET OpenPO = NO where [GPO Invoice Number] = '" & mvalue & "'"
Debug.Print strSql
db.Execute dbFailOnError

db.Close
Set db = Nothing
...

The db.execute here does not have an SQL string to "execute".
 

spikepl

Eledittingent Beliped
Local time
Today, 13:09
Joined
Nov 3, 2010
Messages
6,142
 

twcaddell

Registered User.
Local time
Today, 06:09
Joined
Apr 8, 2013
Messages
31
JDraw - thanks - boy, do I feel stupid on the number of hours I stared at this code. Amazing how it works when you do it write

Spike - here is the complete code
Sub ClosePO_Click()
Dim db As DAO.Database
Dim mvalue As String

Set db = CurrentDb
mvalue = Me.Combo73
strSql = "UPDATE [Print] SET OpenPO = NO where [GPO Invoice Number] = '" & mvalue & "'"
Debug.Print strSql
db.Execute strSql, dbFailOnError

db.Close
Set db = Nothing

End Sub

and the debug.print output:
UPDATE [Print] SET OpenPO = NO where [GPO Invoice Number] = '40328'
Thanks for your assist, particularly the URL that lists reserved words. I will go back through my code and change the Print table name to PrintOrderTbl

Again, thanks to both of you

TC
 

Users who are viewing this thread

Top Bottom