Unless I'm missing something, just change the path in your code to the
path
that you want:
DoCmd.TransferSpreadsheet acExport, 8, List209.Column(0, i), _
"D:\Database\Export Folders\EXCEL\" & List209.Column(0, i) & ".xls",
True, ""
As for printing it, you need to open each query, print it, then close it:
For i = 0 To List209.ListCount - 1
If List209.Selected(i) Then
DoCmd.OpenQuery List209.Column(0, i)
DoCmd.PrintOut
DoCmd.Close acQuery, List209.Column(0, i)
End If
Next i
--
--Roger Carlson
MS Access MVP
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
Roger,
it is working now with this code....
Dim i As Integer
For i = 0 To List209.ListCount - 1
If List209.Selected(i) Then
DoCmd.TransferSpreadsheet acExport, 8, List209.Column(0, i), _
"D:\Database\Export Folders" & List209.Column(0, i) & ".xls", True,
""
End If
..........
NOW I WANT TO EXPORT THE SELECTED QUERIES TO THIS PATHNAME
D:\Database\Export Folders\EXCEL
I TRY ALREADY TO WRITE THIS ONE IN THE CODE BUT IT EXPORT ONLY TO
D:\Databse\Export Folders
SECOND THERE ARE SCENARIO THAT I WANT TO PRINT THE SELECTED QUERY AND
TRY
THIS CODE.....
For i = 0 To List209.ListCount - 1
If List209.Selected(i) Then
DoCmd.PrintOut
End If
BUT IT WILL PRINT THE DISPLAY WINDOWS OF MY DATABASE
HE WILL NOT PRINT THE SELECTED QUERY INSTEAD....
PLEASE HELP ME WHAT CODE DO I NEED TO PRINT THE SELECTED QUERIES FROM
LISTBOX...
THANKS
DENVER
:
In Access 97, there was a bug in the ItemsSelected collection. The
..Selected method was more reliable. I don't know if this bug has
been
corrected in subsequent versions, but I got used to using the
.Selected
method.
--
--Roger Carlson
MS Access MVP
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
Roger,
Is there are reason you would use the entire list rather than this?
Dim varItm As Variant
For Each varItm In Me.MyListBox.ItemsSelected
Docmd.TransferSpreadsheet........
Next varItm
Private Sub cmdExportExcel_Click()
On Error GoTo Err_cmdExportExcel_Click
For i = 0 To MyListBox.ListCount - 1
DoCmd.TransferSpreadsheet acExport, 8, MyListBox.Column(0, i),
_
"C:\" & MyListBox.Column(0, i)& ".xls", True, ""
Next i
Exit_cmdExportExcel_Click:
Exit Sub
Err_cmdExportExcel_Click:
MsgBox Err.Description
Resume Exit_cmdExportExcel_Click
End Sub
Couple of notes: it will export it to the C drive. You can change
that
of course. It will also name the excel file the same as the query
name.
If you wanted to actually select which queries to be printed (a
better
idea in my opinion), it would be something like this:
Private Sub cmdExportExcel_Click()
On Error GoTo Err_cmdExportExcel_Click
For i = 0 To MyListBox.ListCount - 1
If MyListBox.Selected(i) Then
DoCmd.TransferSpreadsheet acExport, 8, MyListBox.Column(0,
i),
_
"C:\" & MyListBox.Column(0, i)& ".xls", True, ""
End If
Next i
Exit_cmdExportExcel_Click:
Exit Sub
Err_cmdExportExcel_Click:
MsgBox Err.Description
Resume Exit_cmdExportExcel_Click
End Sub
--
--Roger Carlson
MS Access MVP
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
I have an unbound form with a list box
that displays all my Queries....
SELECT [Name] FROM MSysObjects WHERE [Type]=5 AND [Name] NOT
LIKE
"~sq_*"
ORDER BY [Name];
I have a cmdButton(Export Excel)
My problem is I don't know how to write or start my codes. so that
when
I
click on it i can export it to excel.i try from the example but no
luck..
any help would be appreciated
thanks
Denver