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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error on Background refresh

Status
Not open for further replies.

msingle

MIS
Jul 15, 2002
22
0
0
US
Private Sub Workbook_Open()
' collect the Database Name and the Server Name
Application.WindowState = xlMaximized

' If Sheet3.Range(&quot;A1&quot;) <> 1 Then
' Sheet3.Range(&quot;A1&quot;) = MsgBox(&quot;Please Create an ODBC DSN 'Insight' before you use this tool&quot;, vbOKOnly + vbInformation)
' End If
'
' If Sheet3.Range(&quot;A1&quot;) = 1 Then
Sheet5.Activate
Sheet5.Range(&quot;R4:S600&quot;).Clear
With ActiveSheet.QueryTables.Add(Connection:= _
&quot;ODBC;DSN=Insight;DRIVER=SQL Server;UID=xxx;PWD=xxx;Network=DBMSSOCN;DATABASE=insight_db_V31&quot; _
, Destination:=Range(&quot;R4&quot;))
.Sql = Array( _
&quot;SELECT devices.Name&quot; & Chr(13) & &quot;&quot; & Chr(10) & &quot;FROM insight_db_v31.dbo.devices devices&quot; & Chr(13) & &quot;&quot; & Chr(10) & &quot;WHERE (devices.ProductType=1)&quot; & Chr(13) & &quot;&quot; & Chr(10) & &quot;ORDER BY devices.Name&quot; _
)
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False

.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.Refresh BackgroundQuery:=False
End With


Sheet1.Activate
Sheet1.ComboBox1.Clear

x = 5
With Sheet1.ComboBox1
.Clear
Do While x < 500
If Sheet5.Range(&quot;R&quot; & x) <> &quot;&quot; Then
.AddItem Sheet5.Range(&quot;R&quot; & x)
End If
x = x + 1
Loop

End With

Sheet2.Activate
Sheet2.ComboBox1.Clear
x = 5
With Sheet2.ComboBox1

.Clear
Do While x < 500
If Sheet5.Range(&quot;R&quot; & x) <> &quot;&quot; Then
.AddItem Sheet5.Range(&quot;R&quot; & x)
End If
x = x + 1
Loop

End With


Sheet4.Activate

x = 5
With Sheet4.s4dnames

.Clear
Do While x < 500
If Sheet5.Range(&quot;R&quot; & x) <> &quot;&quot; Then
.AddItem Sheet5.Range(&quot;R&quot; & x)
End If
x = x + 1
Loop

End With


Sheet3.Range(&quot;B5:p40&quot;).Clear
Sheet5.Range(&quot;D4:K100&quot;).Clear
Sheet3.Visible = xlSheetHidden
Sheet5.Visible = xlSheetHidden
'Sheet3.Visible = xlSheetVisible
'Sheet5.Visible = xlSheetVisible

Sheet6.Activate
ThisWorkbook.Save

' End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top