Solved Previous code not working Search and Export an excel sheet. (1 Viewer)

smtazulislam

Member
Local time
Today, 14:47
Joined
Mar 27, 2020
Messages
806
try again.
Hello Sir @arnelgp
is it possible that If I Format a sample Excel Worksheet same data with columns. Then new data will replace in the sample WorkSheet ?
But File name need and Path should be as before.
Previously your code added here,

Code:
  Const conPath As String = "F:\3. EMPLOYEES Department\Employee's INSURANCE\1. BUPA ARABIA\"
  Dim strFile As String
  Dim varItem As Variant
  Dim varSelect As Variant
  Dim strDataString As String

  strFile = conPath & "CCHI " & (Format$(Date, "dd")) & " " & UCase(MonthName(Month(Date), True)) & " " & Year(Date)
  
    For Each varSelect In Me!lstResults.ItemsSelected
        strDataString = strDataString & Me!lstResults.ItemData(varSelect) & ","
    Next
    If Len(strDataString) Then
        strDataString = "SELECT * FROM (" & Me!lstResults.RowSource & ") where EmployeeID In (" & strDataString & ");"
        Dim qd As DAO.QueryDef
        On Error Resume Next
        DoCmd.DeleteObject acQuery, "QryTempHealthInsIqamaUpdateResults"
        With CurrentDb
            Set qd = .CreateQueryDef("QryTempHealthInsIqamaUpdateResults", strDataString)
            .QueryDefs.Append qd
            Set qd = Nothing
            .QueryDefs.Refresh
        End With
        Application.RefreshDatabaseWindow
      
        DoCmd.TransferSpreadsheet TransferType:=acExport, _
                                  spreadsheetType:=acSpreadsheetTypeExcel12Xml, _
                                  tableName:="CCHI", _
                                  Filename:=strFile
        MsgBox "Your Selected Data has been an export successfully.", vbOKOnly, "Export Completed !"
        'Dim xlApp As Object
        'Set xlApp = CreateObject("Excel.Application")
        'xlApp.Workbooks.Open (strFile)
        'xlApp.Visible = True
    
    End If

EDIT :
Any Temp query QryTempHealthInsIqamaUpdateResults data insert in sample Format workSheet.
AND also would like to open this worksheet when EXPORT is completed.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:47
Joined
May 7, 2009
Messages
19,230
let me clarify.
you are Exportin table CCHI, correct?
and you want to Append (to the last row?) records from "QryTempHealthInsIqamaUpdateResults"?
 

smtazulislam

Member
Local time
Today, 14:47
Joined
Mar 27, 2020
Messages
806
let me clarify.
you are Exportin table CCHI, correct?
YES, this is the WorkSheet name & table name.
And File is "strFile = conPath & "CCHI " & (Format$(Date, "dd")) & " " & UCase(MonthName(Month(Date), True)) & " " & Year(Date)"
let me clarify.
and you want to Append (to the last row?) records from "QryTempHealthInsIqamaUpdateResults"?
this temp query data result want to replace in my sample an Excal file which name is "SAMPLE CCHI"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:47
Joined
May 7, 2009
Messages
19,230
on post#23, what do you mean by this:

"this temp query data result want to replace in my sample an Excal file which name is "SAMPLE CCHI"
 

smtazulislam

Member
Local time
Today, 14:47
Joined
Mar 27, 2020
Messages
806
on post#23, what do you mean by this:

"this temp query data result want to replace in my sample an Excal file which name is "SAMPLE CCHI"
When I selected rows from Search Result then It is keep in the Query of "QryTempHealthInsIqamaUpdateResults". Am I right?
So, when I click the export button then this query data will export into path where I direct.
This step you done already.

Here I need some chance.
I create an excel file which name is "Sample CCHI" in same path where the file will export.
I need THIS SAMPLE SHEET taken only FORMAT and insert data that said.
 

smtazulislam

Member
Local time
Today, 14:47
Joined
Mar 27, 2020
Messages
806
why I can't upload the .zip or .rar file
1658914952851.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:47
Joined
May 7, 2009
Messages
19,230
you have google drive, onedrive, etc.
upload it there and give me the shared link.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:47
Joined
May 7, 2009
Messages
19,230
you need to change it to your own folder/and filename.
 

Attachments

  • export some columns in Excel (2).accdb
    2 MB · Views: 73

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:47
Joined
May 7, 2009
Messages
19,230
the format will be applied to the Exported sheet not the Sample.
 

Attachments

  • export some columns in Excel (2).accdb
    708 KB · Views: 76

smtazulislam

Member
Local time
Today, 14:47
Joined
Mar 27, 2020
Messages
806
Thank you very much, Now work perfectly...
possible after export can open excel file directly...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:47
Joined
May 7, 2009
Messages
19,230
add this code after showing the Msgbox:

...
...
MsgBox "Your Table Export Process successfully.", vbOKOnly, "Export completed!"
'show the excel file
Application.FollowHyperlink strFile
 

smtazulislam

Member
Local time
Today, 14:47
Joined
Mar 27, 2020
Messages
806
add this code after showing the Msgbox:

...
...
MsgBox "Your Table Export Process successfully.", vbOKOnly, "Export completed!"
'show the excel file
Application.FollowHyperlink strFile
Not work...
 

Users who are viewing this thread

Top Bottom