Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query error in VB # 3067 1

Status
Not open for further replies.

sonikudi

Technical User
Sep 9, 2007
81
US
Hey guys,

Followin is my query that gives me the error saying "Query input must contain at least one table or query" for the StrSQL2. StrSQL qry works fine, does exactly what its supposed to do

Code:
Private Sub Graph_it_Click()

Dim StrSQL As String
Dim StrSQL2 As String
Dim qdf As QueryDef
Dim stDocName As String
stDocName = "StaubGraphs"

    
On Error GoTo qry

' Deletes the queri if it exists


qry:

SrtSQL = "SELECT [Item Num], [Shipment Date], SUM([Num Defected]) AS SumNumDefected, SUM([Batch Size]) AS SumBatchSize " & _
"FROM [incoming inspec staub parts] " & _
"WHERE Vendor= 'Staub' And [Shipment Date] Between #" & _
Me.txtStartDate & "# AND #" & Me.txtEndDate & "# GROUP BY [Item Num],[Shipment Date];"
CurrentDb.QueryDefs.Delete ("qryStaubUpdateVB")
' Create new QueryDef object, don't really need it once the query exists
Set qdf = CurrentDb.CreateQueryDef("qryStaubUpdateVB", SrtSQL)



[red]StrSQL2 = "SELECT t1.[Item Num], t2.Description, t1.[Shipment Date],(t1.SumNumDefected/t1.SumBatchSize)*100 AS PercentRejected into table1" & _
"FROM qryStaubUpdateVB AS t1, [Item numbers] AS t2 WHERE (t1.[Item Num])=(t2.[Item Num]);"[/red]

CurrentDb.Execute StrSQL2, dbFailOnError

DoCmd.Close acForm, "GetGraphDatesStaub", acSaveNo

CurrentDb.TableDefs.Delete ("qrySummaryStaubTable")
CurrentDb.TableDefs.Refresh
CurrentDb.QueryDefs.Refresh
Set dbs = Nothing
End Sub

Any help on the cause of the error will be much appreciated..thanks
 
Am I reading it wrong - it looks like you are deleting qryStaubUpdateVB a few lines before trying to run strSQL2.
 
Add a space before the FROM keyword.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
hi PH,

Thanks for the tip. It worked!! its the smallest thing that drives you crazy..!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top