I'm new to VBA coding so bear with me.
I have a table that needs to get into Excel. The worksheet is important, but not necessarily the range. I would like to export using a recordset and have the user able to select the excel file (which is a template of sorts). I got a lot of help from previous posts, but with the following code, nothing is happening at all. No error message or anything. "GroupImport" is the range on the sheet "SB-UW".
On Error GoTo ErrHandler
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim xl As Excel.Application
Dim wb As Excel.Workbook
Dim sht As Excel.Worksheet
Dim rng As Excel.Range
Dim FileName As String
strSQL = "SELECT * FROM [tblGroups]"
strSQL = strSQL & "WHERE [AccountID] = '" & Me.[AccountID] & "'"
strSQL = strSQL & "ORDER BY [Group1-6]"
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
With rst
If .RecordCount > 0 Then
Set xl = Excel.Application
FileName = xl.Application.GetOpenFilename _
("xls files(*.xls),*.xls,rpt02 files(*.rpt02),*.rpt02,all files (*.*),*.*,Text Files (*.TXT), *.txt,CSV Files (*.Csv), *.Csv"
xl.Visible = True
xl.DisplayAlerts = False
Set wb = xl.Workbooks.Open(FileName, AddToMRU:=False)
Set sht = wb.Sheets("SB-UW"
While Not .EOF
Set rng = sht.Range("GroupImport"
.MoveNext
Wend
End If
End With
ExitHere:
On Error Resume Next
wb.Close True
xl.Quit
Exit Sub
ErrHandler:
Debug.Print Err, Err.Description
Resume ExitHere
Any help would be greatly appreciated.
blreid
I have a table that needs to get into Excel. The worksheet is important, but not necessarily the range. I would like to export using a recordset and have the user able to select the excel file (which is a template of sorts). I got a lot of help from previous posts, but with the following code, nothing is happening at all. No error message or anything. "GroupImport" is the range on the sheet "SB-UW".
On Error GoTo ErrHandler
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim xl As Excel.Application
Dim wb As Excel.Workbook
Dim sht As Excel.Worksheet
Dim rng As Excel.Range
Dim FileName As String
strSQL = "SELECT * FROM [tblGroups]"
strSQL = strSQL & "WHERE [AccountID] = '" & Me.[AccountID] & "'"
strSQL = strSQL & "ORDER BY [Group1-6]"
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
With rst
If .RecordCount > 0 Then
Set xl = Excel.Application
FileName = xl.Application.GetOpenFilename _
("xls files(*.xls),*.xls,rpt02 files(*.rpt02),*.rpt02,all files (*.*),*.*,Text Files (*.TXT), *.txt,CSV Files (*.Csv), *.Csv"
xl.Visible = True
xl.DisplayAlerts = False
Set wb = xl.Workbooks.Open(FileName, AddToMRU:=False)
Set sht = wb.Sheets("SB-UW"
While Not .EOF
Set rng = sht.Range("GroupImport"
.MoveNext
Wend
End If
End With
ExitHere:
On Error Resume Next
wb.Close True
xl.Quit
Exit Sub
ErrHandler:
Debug.Print Err, Err.Description
Resume ExitHere
Any help would be greatly appreciated.
blreid