Exporting Access table to excel table

  • Thread starter Thread starter TaylorBo
  • Start date Start date
T

TaylorBo

Guest
I'm trying to figure out what the code is in order for me to do the following...

I have the code below which exports an access file to an excel file. Currently it exports the file to a set folder. What code will enable a prompt so that the user can select where to export and save the file to? It's a "save as" type function I'd think, but I'm not super familar with VBA.

Thanks.

Code:
Private Sub Command1_Click()
'***EXCEL EXPORT
On Error GoTo COMMAND1_Click_ERR
   Call Msg_Box(36)
    If G_MSGKBN = 2 Then
        Exit Sub
    End If
Dim Q_T_SHADAI_EXCEL  As QueryDef
Dim F_NUM As Double
    
    'FILECD GA EXCEL NI MAJITTARA ERROR
    F_NUM = DCount("FILECD", "V_PLAN", "FILECD <> '" & G_FILECD & "'")
    If F_NUM <> 0 Then
        Call Msg_Box(7)
        Exit Sub
    End If

    'DATA DELETE
    Kill "C:\GNENKEI\VEHICLE_PLAN.XLS"
    
    'FONT CHANGE
    Call ole_Exl_font("Q_T_SHADAI_SUB", "C:\GNENKEI\VEHICLE_PLAN.XLS")
    
    'EXPORT
    Shell (EXCEL_PG & "C:\GNENKEI\VEHICLE_PLAN.XLS")
    
    Exit Sub
 
Take a look in Access Help under "TransferSpreadsheet." It does most of the coding.

As for choosing the target directory and filename, I use the commondialog directX control. I'm using Access97, and the CommonDialog control was only available with the Developer Edition Tools which was sold as a separate item. I'm not sure what it's status is in post-97 versions.

I'm sure SOMEBODY else out there knows!
 
Stick this on a command button and it will prompt you where to save the excelfile (replace YOUR_TABLE_NAME with the tablename - of course)



Code:
On Error GoTo Error
    
DoCmd.OutputTo acTable, "YOUR_TABLE_NAME", "MicrosoftExcelBiff8(*.xls)", "", False, "", 0
    
Error:     MsgBox Err.Description
Exit Sub
 
mikebaldam said:
Stick this on a command button and it will prompt you where to save the excelfile (replace YOUR_TABLE_NAME with the tablename - of course)



Code:
On Error GoTo Error
    
DoCmd.OutputTo acTable, "YOUR_TABLE_NAME", "MicrosoftExcelBiff8(*.xls)", "", False, "", 0
    
Error:     MsgBox Err.Description
Exit Sub


thank you very much for your code.I want to ask 2 question

first one is when I use this code to export data from access to excel , I saw a message dialog box.But this dialog box is empty.Is that possible to give a succesful message in this diaolog box?

the second question is , this code is record excel 5-7 format.how can I record excel 2000-2003 format?
 

Attachments

  • photo1.JPG
    photo1.JPG
    6.2 KB · Views: 185
  • photo2.JPG
    photo2.JPG
    9.3 KB · Views: 160
this is great, this does a lot of what I want, but i want to tweak it 1 step further , I want to have a button on a form to do this, but also have a text field onth e form to state the location example C:\\temp\test.xls

this would let you name the location and allow you to rename file/location

regards
 

Users who are viewing this thread

Back
Top Bottom