kermitforney
Technical User
Having a n issue with ShellExecute where the file is being deleted instead of opened. Usually during this process a SQL Server Stored Procedure is called followed by an Excel file being opened, but for some reason the file is being deleted.
Not sure why and unfortunately I am not too familiar with VBA.
Any help would be greatly appreciated.
Not sure why and unfortunately I am not too familiar with VBA.
Any help would be greatly appreciated.
Code:
Private Sub Command0_Click()
Dim cmd As ADODB.Command
Dim prm As ADODB.Parameter
Dim strOpComp As String
Dim strDiv As String
Dim i As Variant
strOpComp = "ALL"
strDiv = "ALL"
DoCmd.Hourglass True
Set cmd = New ADODB.Command
If Me.frmFilter.Value = 2 And Me.lstOperatingCompanies.ItemsSelected.Count > 0 Then
strOpComp = ""
For Each i In Me.lstOperatingCompanies.ItemsSelected
strOpComp = strOpComp + Me.lstOperatingCompanies.ItemData(i) + ","
Next i
End If
If Me.frmFilter.Value = 3 And Me.lstDivisions.ItemsSelected.Count > 0 Then
strDiv = ""
For Each i In Me.lstDivisions.ItemsSelected
strDiv = strDiv + Me.lstDivisions.ItemData(i) + ","
Next i
End If
With cmd
.ActiveConnection = CurrentProject.Connection
.CommandTimeout = 1200
.CommandType = adCmdStoredProc
.CommandText = "stpItemSalesByDateRange_XLS"
Set prm = .CreateParameter("@StartDate", adDate, adParamInput, , Me.txtStart.Value)
.Parameters.Append prm
Set prm = .CreateParameter("@EndDate", adDate, adParamInput, , Me.txtEnd.Value)
.Parameters.Append prm
Set prm = .CreateParameter("@OperatingCompanies", adVarChar, adParamInput, 300, strOpComp)
.Parameters.Append prm
Set prm = .CreateParameter("@Divisions", adVarChar, adParamInput, 300, strDiv)
.Parameters.Append prm
.Execute
End With
DoCmd.Hourglass False
'ShellExecute 0, vbNullString, "\\SNLSQL001\ATA\IT\SalesDetail.xls", vbNullString, vbNullString, vbNormalFocus
ShellExecute 0&, vbNullString, "\\SNLSQL001\ATA\IT\SalesDetail.xls", vbNullString, vbNullString, SW_SHOWNORMAL
End Sub