G
Guest
Hi :
What is wrong with this code?
When I run it I get the above error:
Private Sub Command70_Click()
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim BaseSQL As String
Dim strSQL As String
Set rst = CurrentDb.OpenRecordset(("SELECT DISTINCT [natl_str_nbr] FROM
[Invalid MI after depl to run]"), dbOpenDynaset, dbReadOnly)
Set qdf = CurrentDb.QueryDefs("[Invalid Mi after depl to run]")
BaseSQL = Left(qdf.SQL, Len(qdf.SQL) - 3)
With rst
Do Until .EOF
strSQL = BaseSQL & " WHERE natl_str_nbr=" & ![NATL_STR_NBR]
qdf.SQL = strSQL
DoCmd.OutputTo acOutputReport, "[Invalid Mi to run]", _
"SnapshotFormat", "C:\Documents and Settings\dpopescu\Desktop\te\" &
![NATL_STR_NBR] & ".snp"
.MoveNext
Loop
.Close
End With
qdf.SQL = BaseSQL
Set qdf = Nothing
Set rst = Nothing
End Sub
*************The SQL is:
SELECT DISTINCT ODSDBA_WATP1MIT.MENU_ITEM_CD, ODSDBA_WATP1MIT.MENU_ITEM_DSC,
ODSDBA_WATS5MIX.DLY_UNT_SLS_QTY, ODSDBA_WATS5MIX.NATL_STR_NBR,
ODSDBA_WATS5MIX.DLY_SLS_DT, [DS Complete].[Site Description], [DS
Complete].City, [DS Complete].Prov, IIf([Owner Type]="M",[Business/Ops
Consultant],[Franchisee]) AS Expr1, IIf([Owner Type]="M","Ops.
Consultant","Franchisee") AS Expr2, [DS Complete].[BO Mobil], [DS
Complete].[BO Office], [DS Complete].[Fran Mobil], [DS Complete].[Owner
Type], [DS Complete].[Fran Office], [DS Complete].[Restaurant Phone #], [DS
Complete].[McOpCo#], [DS Complete].Comp, ODSDBA_WATP1MIT.AMIL_FG,
ODSDBA_WATP1MIT.MENU_ITEM_STS, IIf([dly_sls_dt]>[comp],"Contact
Store?","Ignore") AS Expr3
FROM (ODSDBA_WATP1MIT INNER JOIN ODSDBA_WATS5MIX ON
ODSDBA_WATP1MIT.MENU_ITEM_CD = ODSDBA_WATS5MIX.MENU_ITM_NBR) INNER JOIN [DS
Complete] ON ODSDBA_WATS5MIX.NATL_STR_NBR = [DS Complete].[Natl#]
WHERE (((ODSDBA_WATS5MIX.DLY_SLS_DT) Between [SD] And Date()) AND
((ODSDBA_WATP1MIT.AMIL_FG)="N") AND ((ODSDBA_WATP1MIT.MENU_ITEM_STS) Not Like
"T") AND ((IIf([dly_sls_dt]>[comp],"Contact Store?","Ignore")) Like "Contact
Store?"));
***********
Thank you,
Dan
What is wrong with this code?
When I run it I get the above error:
Private Sub Command70_Click()
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim BaseSQL As String
Dim strSQL As String
Set rst = CurrentDb.OpenRecordset(("SELECT DISTINCT [natl_str_nbr] FROM
[Invalid MI after depl to run]"), dbOpenDynaset, dbReadOnly)
Set qdf = CurrentDb.QueryDefs("[Invalid Mi after depl to run]")
BaseSQL = Left(qdf.SQL, Len(qdf.SQL) - 3)
With rst
Do Until .EOF
strSQL = BaseSQL & " WHERE natl_str_nbr=" & ![NATL_STR_NBR]
qdf.SQL = strSQL
DoCmd.OutputTo acOutputReport, "[Invalid Mi to run]", _
"SnapshotFormat", "C:\Documents and Settings\dpopescu\Desktop\te\" &
![NATL_STR_NBR] & ".snp"
.MoveNext
Loop
.Close
End With
qdf.SQL = BaseSQL
Set qdf = Nothing
Set rst = Nothing
End Sub
*************The SQL is:
SELECT DISTINCT ODSDBA_WATP1MIT.MENU_ITEM_CD, ODSDBA_WATP1MIT.MENU_ITEM_DSC,
ODSDBA_WATS5MIX.DLY_UNT_SLS_QTY, ODSDBA_WATS5MIX.NATL_STR_NBR,
ODSDBA_WATS5MIX.DLY_SLS_DT, [DS Complete].[Site Description], [DS
Complete].City, [DS Complete].Prov, IIf([Owner Type]="M",[Business/Ops
Consultant],[Franchisee]) AS Expr1, IIf([Owner Type]="M","Ops.
Consultant","Franchisee") AS Expr2, [DS Complete].[BO Mobil], [DS
Complete].[BO Office], [DS Complete].[Fran Mobil], [DS Complete].[Owner
Type], [DS Complete].[Fran Office], [DS Complete].[Restaurant Phone #], [DS
Complete].[McOpCo#], [DS Complete].Comp, ODSDBA_WATP1MIT.AMIL_FG,
ODSDBA_WATP1MIT.MENU_ITEM_STS, IIf([dly_sls_dt]>[comp],"Contact
Store?","Ignore") AS Expr3
FROM (ODSDBA_WATP1MIT INNER JOIN ODSDBA_WATS5MIX ON
ODSDBA_WATP1MIT.MENU_ITEM_CD = ODSDBA_WATS5MIX.MENU_ITM_NBR) INNER JOIN [DS
Complete] ON ODSDBA_WATS5MIX.NATL_STR_NBR = [DS Complete].[Natl#]
WHERE (((ODSDBA_WATS5MIX.DLY_SLS_DT) Between [SD] And Date()) AND
((ODSDBA_WATP1MIT.AMIL_FG)="N") AND ((ODSDBA_WATP1MIT.MENU_ITEM_STS) Not Like
"T") AND ((IIf([dly_sls_dt]>[comp],"Contact Store?","Ignore")) Like "Contact
Store?"));
***********
Thank you,
Dan