C
charlienilmag
I'm currently building an inventory program to keep track of hardware.
I've successfully built a search function using multiple parameters.
I'm able to see the results in the recordset as well. What I need to
know is how to export that searched (filtered I guess?) data into
Excel. I've found a couple of topics that guided me in the right
direction, but wasn't quite what I needed. Again, I'd just like to see
the results from the search. Any help would be greatly appreciated.
Thanks in advance.
The code I'm currently using is giving me the entire database table in
Excel. I just want the searched for data.
Private Sub Export_Click()
'Create a Recordset from all the records in the Orders table
Dim Inventory_Database As String
Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
Inventory_Database = "C:\Documents and Settings\cnilmag\My
Documents\Inventory\Inventory Program\Inventory_Database.mdb"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Inventory_Database & ";"
conn.CursorLocation = adUseClient
Set rs = conn.Execute("Inventory_Database", , adCmdTable)
'Create a new workbook in Excel
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
'Transfer the data to Excel
oSheet.Range("A1").CopyFromRecordset rs
'Save the Workbook and Quit Excel
oBook.SaveAs "C:\Book1.xls"
oExcel.Quit
'Close the connection
rs.Close
conn.Close
End Sub
I've successfully built a search function using multiple parameters.
I'm able to see the results in the recordset as well. What I need to
know is how to export that searched (filtered I guess?) data into
Excel. I've found a couple of topics that guided me in the right
direction, but wasn't quite what I needed. Again, I'd just like to see
the results from the search. Any help would be greatly appreciated.
Thanks in advance.
The code I'm currently using is giving me the entire database table in
Excel. I just want the searched for data.
Private Sub Export_Click()
'Create a Recordset from all the records in the Orders table
Dim Inventory_Database As String
Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
Inventory_Database = "C:\Documents and Settings\cnilmag\My
Documents\Inventory\Inventory Program\Inventory_Database.mdb"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Inventory_Database & ";"
conn.CursorLocation = adUseClient
Set rs = conn.Execute("Inventory_Database", , adCmdTable)
'Create a new workbook in Excel
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
'Transfer the data to Excel
oSheet.Range("A1").CopyFromRecordset rs
'Save the Workbook and Quit Excel
oBook.SaveAs "C:\Book1.xls"
oExcel.Quit
'Close the connection
rs.Close
conn.Close
End Sub