Can anyone help me figure out why I continue to get a runtime error '3010' "TABLE qryMultiSelect ALREADY EXISTS'? Here is my code. thank you in advance for any help!!!
Code:
Private Sub cmbSelectionDone_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryMultiSelect")
If Me!cboxRangeName = -1 Then
myPath = txtFilePath & txtFileName
myFileName = Me!txtFileName
DoCmd.SetWarnings (False)
DoCmd.RunSQL "DELETE * FROM TempSymbol"
DoCmd.SetWarnings (True)
DoCmd.TransferSpreadsheet acImport, , "TempSymbol", "" & myPath & "", True, "" & txtRangeName & ""
MsgBox "The symbols have been successfully imported."
strSQL = "SELECT DailyPrice.Symbol, DailyPrice.LocateDate, DailyPrice.MarketPrice, DailyPrice.PriceFlag " & _
"FROM TempSymbol, DailyPrice " & _
"WHERE (((DailyPrice.Symbol) = [TempSymbol]![Symbol])) " & _
"ORDER BY DailyPrice.Symbol, DailyPrice.LocateDate;"
qdf.SQL = strSQL
'check this out...maybe delete it later
qdf.Close
DoCmd.TransferSpreadsheet acExport, , "qryMultiSelect", "" & myPath & ""
MsgBox "The table have been successfully exported to " & myFileName & "."
Set db = Nothing
Set qdf = Nothing
Exit Sub
End If
'DoCmd.TransferSpreadsheet acExport, , "qryMultiSelect", "" & myPath & ""
If IsNull(txtGetList) Then
For Each varItem In Me!lstSelectSymbol.ItemsSelected
strCriteria = strCriteria & "'" & Me!lstSelectSymbol.ItemData(varItem) & "',"
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list", vbExclamation, "Nothing to find!"
Set db = Nothing
Set qdf = Nothing
Me!lstSelectSymbol.SetFocus
Exit Sub
End If
strCriteria = Left(strCriteria, Len(strCriteria) - 1)
myPath = txtFilePath & txtFileName
myFileName = Me!txtFileName
strSQL = "SELECT DailyPrice.Symbol, DailyPrice.LocateDate, DailyPrice.MarketPrice, DailyPrice.PriceFlag FROM DailyPrice " & _
"WHERE DailyPrice.Symbol IN (" & strCriteria & ") " & _
"ORDER BY DailyPrice.Symbol, DailyPrice.LocateDate;"
qdf.SQL = strSQL
DoCmd.TransferSpreadsheet acExport, , "qryMultiSelect", "" & myPath & ""
MsgBox "The table have been successfully exported to " & myFileName & "."
qdf.Close
Set db = Nothing
Set qdf = Nothing
Exit Sub
End If
strCriteria = Me!txtGetList
myPath = txtFilePath & txtFileName
myFileName = Me!txtFileName
' On Error GoTo Do_Nothing
strSQL = "SELECT DailyPrice.Symbol, DailyPrice.LocateDate, DailyPrice.MarketPrice, DailyPrice.PriceFlag FROM DailyPrice " & _
"WHERE DailyPrice.Symbol IN (" & strCriteria & ") " & _
"ORDER BY DailyPrice.Symbol, DailyPrice.LocateDate;"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryMultiSelect"
DoCmd.TransferSpreadsheet acExport, , "qryMultiSelect", "" & myPath & ""
MsgBox "The table have been successfully exported to " & myFileName & "."
qdf.Close
Set db = Nothing
Set qdf = Nothing
End Sub
Comment