export data in Listbox to excel

koketsomaseko

Registered User.
Local time
Today, 04:01
Joined
Jun 17, 2014
Messages
11
I have a Listbox named List5 and a search textbox named txtProperty and a table name sms , after i search in textbox the results in listbox . i would link to inport the results in listbox to excel but the code i have export the whole table to excel , please help:


here is my code

''''''''*''''''''*''''''''*''''''''*''''''''*''''''''*''''''''*''''''''*'
''''''''*''''''''*'''''''' BUTTON 3 ''''''''*''''''''*''''''''*'''''''
''' EXPORT THE LIST TO EXCEL AS List5.XLS ''''''''*''''''''*''
''''''''*''''''''*''''''''*''''''''*''''''''*''''''''*''''''''*''''''''*'
''''''''*''''''''*''''''''*''''''''*''''''''*''''''''*''''''''*''''''''*'

Dim outputFileName As String

Dim oXL As Object
Dim oExcel As Object
Dim sFullPath As String
Dim sPath As String


outputFileName = CurrentProject.Path & "\List5.xls"

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, _
"sms", _
outputFileName, _
True ' HasFieldNames

MsgBox "Data has been exported to " & outputFileName


' Create a new Excel instance
Set oXL = CreateObject("Excel.Application")

' Only XL 97 supports UserControl Property
On Error Resume Next
oXL.UserControl = True
On Error GoTo 0


sFullPath = outputFileName

' Open it
With oXL
.Visible = True
.Workbooks.Open (sFullPath)
End With
 
It would help if you could include what issues/errors you are running into when you attempt to run your code, this way the person trying help does not have to disect the entire block of code :) (It's also helpfull ito know if you wrote the code or not) :)
 
Well when i press the Export button , it exports the whole entire table rather than exporting the Listbox search pleas find the attached photos
 

Attachments

  • Search.jpg
    Search.jpg
    75.9 KB · Views: 135
  • excel.jpg
    excel.jpg
    98.9 KB · Views: 152

Users who are viewing this thread

Back
Top Bottom