Private Sub UserForm_Initialize() Dim DefaultSources(10) As String Dim Looper As Long, Buildup As String Dim objanFSO As Scripting.FileSystemObject, objAnOpenFile As Scripting.TextStream Set objanFSO = New Scripting.FileSystemObject On Error Resume Next Set objAnOpenFile = objanFSO.OpenTextFile(gblOutputResultsPath & _ gblDefaultFileName, ForReading, False, TristateUseDefault) If Err.Number = 0 Then On Error GoTo 0 Buildup = "" While Not objAnOpenFile.AtEndOfStream Buildup = Buildup & objAnOpenFile.ReadLine & vbCrLf Wend TxtbxQueryArea.Value = Buildup Else On Error GoTo 0 TxtbxQueryArea.Value = "" End If TxtbxNumRecordswanted.Value = 10 DefaultSources(1) = "someserver" For Looper = 1 To UBound(DefaultSources) If Len(DefaultSources(Looper)) > 0 Then CmbobxServers.AddItem (DefaultSources(Looper)) End If Next CmbobxServers.Value = CmbobxServers.List(0) lblStatusWindow.Caption = "Ready." lblfiveS.Caption = ActiveWorkbook.FullName Application.Goto Reference:=Worksheets("Data").Range("A1"), _ scroll:=True End Sub Private Sub CmdGetData_Click() Dim SelectedSQL As String If Len(TxtbxQueryArea.SelText) > 0 Then SelectedSQL = TxtbxQueryArea.SelText Else SelectedSQL = TxtbxQueryArea.Value End If Controls("lblStatusWindow").Caption = "Processing Query..." FastDMRtoExcel SelectedSQL, TxtbxNumRecordswanted.Value, CmbobxServers.Value End Sub Private Sub CmdKill_Click() Worksheets("Data").Cells.Clear Application.Goto Reference:=Worksheets("Data").Range("A1"), _ scroll:=True End Sub Private Sub cmdOpen_Click() Dim strFileChosen As Variant, Buildup As String Dim objanFSO As Scripting.FileSystemObject Dim objAnOpenFile As Scripting.TextStream Set objanFSO = New Scripting.FileSystemObject strFileChosen = Application.GetOpenFilename("Text Files (*.txt),*.txt,SQL Files " & _ "(*.sql;*.tql),*.sql;*.tql", 2, "Open SQL File", , False) If strFileChosen = "False" Then ' do nothing; user chose cancel button Else Set objAnOpenFile = objanFSO.OpenTextFile(strFileChosen, ForReading, False, _ TristateUseDefault) Buildup = "" While Not objAnOpenFile.AtEndOfStream Buildup = Buildup & objAnOpenFile.ReadLine & vbCrLf Wend TxtbxQueryArea.Value = Buildup objAnOpenFile.Close End If Set objanFSO = Nothing End Sub Private Sub cmdSave_Click() Dim objDataSheet As Worksheet, TheFileName As String ActiveWorkbook.SaveCopyAs "c:\temp.xls" Workbooks.Open "c:\temp.xls" Workbooks("temp.xls").Activate ActiveWorkbook.Worksheets("GenericQueryAnalyzer").Delete TheFileName = Application.GetSaveAsFilename("data.csv", _ "Comma-delimited Flatfiles (*.csv), *.csv", _ 1, "Save Results to Flat File") ActiveWorkbook.Worksheets("Data").SaveAs TheFileName & "data.csv", xlCSVWindows ActiveWorkbook.Close End Sub Private Sub SpnNumRecordsWanted_SpinDown() TxtbxNumRecordswanted.Value = TxtbxNumRecordswanted.Value - 1 If TxtbxNumRecordswanted.Value < 0 Then TxtbxNumRecordswanted.Value = 0 End Sub Private Sub SpnNumRecordsWanted_SpinUp() TxtbxNumRecordswanted.Value = TxtbxNumRecordswanted.Value + 1 End Sub