Back again with more questions and request for assistance....
Using the "File/Open Dialog API" from
http://www.mvps.org/access/api/api0001.htm, I have created the
following function to allow the user to select either - dbf, xls or
csv(txt) - when exporting data (query or table) to a file.
Function Export_File_Choices()
On Error GoTo Export_File_Choices_Err
Dim strFilter As String
Dim varFileName As String
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.dbf")
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", "*.xls")
strFilter = ahtAddFilterItem(strFilter, "CSV Files (*.csv)", "*.csv")
varFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
InitialDir:="F:\", _
Filter:=strFilter, _
FilterIndex:=2, _
DialogTitle:="Save File As...")
Select Case Right(varFileName, 1)
Case Is = "F"
DoCmd.TransferDatabase acExport, "dBase IV", Left(varFileName, 3),
acTable, "tblCarcass", RTrim(Mid(varFileName, 4, 20)), False
Case Is = "S"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97,
"tblCarcass", varFileName, True
Case Is = "V"
DoCmd.TransferText acExportDelim, "Carcass Export Specification",
"tblCarcass", varFileName
End Select
If varFileName = "" Then
MsgBox "No File exported.", vbInformation
Exit Function
End If
Export_File_Choices_Cont:
MsgBox "File exported successfully.", vbInformation
Exit Function
Export_File_Choices_Err:
Select Case Err
'Handle a specific error here
Case 1
MsgBox "Error has occurred"
'Any other error
Case Else
MsgBox Err.Description, vbCritical
End Select
Resume Export_File_Choices_Cont
End Function
What I would appreciate very much is:
1. If someone can improve it for me
2. If someone could suggest how to make the function "Generic" i.e. if
the table name could be passed as a variable from a call
3. If someone could suggest how to incorporate a "DAO Recordset" for
example when typically used with writing to a file using "Print # or
Write #"
Apologies for any word wrap. Thanks for any suggestions and
solutions....
osmethod