I have written this code for extract button. It works perfectly. What I'd like to do is have the Excel app open and show the data in the sheet. For now after every extract I have to go to the c:
drive in order to see the spreadsheet. Also, is there a way to autofit the columns, change header color. Thanks!
Dim FileNum As Integer
Dim strSQL As String
Dim rs As ADODB.Recordset
Dim strFileName As String
FileNum = FreeFile
strFileName = "C:\Test\TESTFILE.CSV"
Open strFileName For Output As #FileNum
Write #FileNum, "ID", "FirstName", "LastName", "DOB", "SSN", "SEX"
Set rs = New ADODB.Recordset
strSQL = "Select ID, FirstName, LastName, DOB, SSN, Sex from dbo.tblTest_Clients Where ID = " & g_lngSelectedID
rs.Open strSQL, g_cnDatabase
rs.MoveFirst
Do While Not rs.EOF
Write #FileNum, rs("ID") & vbTab; rs("FirstName") & vbTab; rs("LastName") & vbTab; rs("DOB") & vbTab; rs("SSN") & vbTab; rs("Sex")
rs.MoveNext
Loop
rs.Close
Close #FileNum