All,
I am using the following adapted code to export a filtered recordset from a search form in to excel:
This does everything as I want however, whenever it comes to a value that is depicted in a combo box it exports the bound column value which is an ID value within my sub tables. The unbound column (text I wish to see) is what is displayed in the actual search form.
How can I edit the above code to export the unbound column? which would be column 1 where the bound is column 0.
The form is filtering a recordset produced from a query just so you know.
Output is shown above. Ignore all the dates being shown as serials this is because I have yet to set any cell formats but as you can see, the textbox field shows up correctly as "aerofoil milling" the other boxes are on the whole combo and show bound columns.
I am using the following adapted code to export a filtered recordset from a search form in to excel:
Code:
Option Explicit
Private Sub btnexcelexport_Click()
'revised for late binding
'define variables
Dim xlApp As Object
Dim xlWorkbook As Object
'create the excel application object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
'create a new workbook
Set xlWorkbook = xlApp.Workbooks.Add
'define variables
Dim objRST As Recordset
Dim strSheetname As String
'create the recordset
Set objRST = Screen.ActiveForm.RecordsetClone
'create a sheet name - must be 30 characters or less
strSheetname = "NCC Export - " & Format(Date, "dd.mm.yyyy")
'copy data from the recordset to the cells
Dim xlsheet As Object
Set xlsheet = xlWorkbook.Sheets(1)
With xlsheet
.Cells.CopyFromRecordset objRST
.Name = strSheetname
End With
'clean up all variables
Set objRST = Nothing
Set xlsheet = Nothing
Set xlWorkbook = Nothing
Set xlApp = Nothing
End Sub
How can I edit the above code to export the unbound column? which would be column 1 where the bound is column 0.
The form is filtering a recordset produced from a query just so you know.
Code:
521 40364 40361 9 9 12 Aerofoil milling 1 14 1260
Comment