I had this code working and for some reason it is blowing up at my line: qdf.SQL = strSQL. I am pulling my hair out...any help!!????
Private Sub comboExcelForVe ndor_AfterUpdat e()
On Error GoTo Err_MyProc
Dim dbs As DAO.Database, qdf As DAO.QueryDef, strSQL As String
Set dbs = CurrentDb
Dim strTableName, strClient, strExcelName, strDate As String
Dim myPos
strTableName = Forms!frmDailyC lient!comboExce lforVendor
myPos = InStr(1, strTableName, "_", vbTextCompare) - 1
strExcelName = Left(strTableNa me, myPos)
strDate = Right(strTableN ame, 7)
Set qdf = dbs.QueryDefs(" qryCreateExcel" )
strSQL = "SELECT TOP 20 " & strTableName & ".Symbol, " & strTableName & ".Cusip, Sum(" & strTableName & ".TotalQty) AS SumOfTotalQty " & _
"FROM " & strTableName & _
"GROUP BY " & strTableName & ".Symbol, " & strTableName & ".Cusip, " & strTableName & ".ML_DailyR ate " & _
"HAVING (((" & strTableName & ".ML_DailyR ate) < 4.5 Or (" & strTableName & ".ML_DailyR ate) = 4.5)) " & _
"ORDER BY Sum(" & strTableName & ".ML_SMV);"
qdf.SQL = strSQL
MsgBox ("After")
DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel9, "qryCreateExcel ", "c:\documen ts and settings\" & mUser & "My Documents\compa nyName\" & strExcelName & "\" & strExcelName & " Rate Request" & strDate & ".xls", True
MsgBox ("File successfully exported")
qdf.Close
Set qdf = Nothing
Set dbs = Nothing
Exit Sub
Exit_MyProc:
qdf.Close
Set dbs = Nothing
Set qdf = Nothing
Exit Sub
Err_MyProc:
Resume Exit_MyProc
End Sub
Private Sub comboExcelForVe ndor_AfterUpdat e()
On Error GoTo Err_MyProc
Dim dbs As DAO.Database, qdf As DAO.QueryDef, strSQL As String
Set dbs = CurrentDb
Dim strTableName, strClient, strExcelName, strDate As String
Dim myPos
strTableName = Forms!frmDailyC lient!comboExce lforVendor
myPos = InStr(1, strTableName, "_", vbTextCompare) - 1
strExcelName = Left(strTableNa me, myPos)
strDate = Right(strTableN ame, 7)
Set qdf = dbs.QueryDefs(" qryCreateExcel" )
strSQL = "SELECT TOP 20 " & strTableName & ".Symbol, " & strTableName & ".Cusip, Sum(" & strTableName & ".TotalQty) AS SumOfTotalQty " & _
"FROM " & strTableName & _
"GROUP BY " & strTableName & ".Symbol, " & strTableName & ".Cusip, " & strTableName & ".ML_DailyR ate " & _
"HAVING (((" & strTableName & ".ML_DailyR ate) < 4.5 Or (" & strTableName & ".ML_DailyR ate) = 4.5)) " & _
"ORDER BY Sum(" & strTableName & ".ML_SMV);"
qdf.SQL = strSQL
MsgBox ("After")
DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel9, "qryCreateExcel ", "c:\documen ts and settings\" & mUser & "My Documents\compa nyName\" & strExcelName & "\" & strExcelName & " Rate Request" & strDate & ".xls", True
MsgBox ("File successfully exported")
qdf.Close
Set qdf = Nothing
Set dbs = Nothing
Exit Sub
Exit_MyProc:
qdf.Close
Set dbs = Nothing
Set qdf = Nothing
Exit Sub
Err_MyProc:
Resume Exit_MyProc
End Sub
Comment