Save dialog box

J

jrt

I have a button on a form that saves a report based off the data in the form.
A dialog box appears for the user to choose the file type but I can't seem to
force the save dialog box to pop up for the user to choose where to save the
file. Any suggestions? - Thank you


Private Sub CmdFileRpt_Click()
On Error GoTo Err_CmdFileRpt_Click

Dim RptName As String

RptName = "Infection Control Report" & " " & [LstName] & " " & [AutoNum]

DoCmd.OutputTo acReport, "Infection Control Report", acFormat, RptName

Exit_CmdFileRpt_Click:
Exit Sub

Err_CmdFileRpt_Click:
MsgBox Err.Description
Resume Exit_CmdFileRpt_Click

End Sub
 
J

Jeanette Cunningham

Hi,
here is a function I use in my databases to get the location to save the
file to when I want to export to excel.

Public Function MySavePath(strFileName As String, _

Optional varDirectory As Variant, _

Optional varTitleForDialog As Variant) As
Variant



Dim strFilter As String

Dim strSaveFileName As String 'name to save file as

Dim strPath As String 'new file save as name

Dim lngFlags As Long



' don't bother displaying the read-only box. It'll only confuse people.

lngFlags = ahtOFN_HIDEREADONLY



If IsMissing(varDirectory) Then

varDirectory = ""

End If



If IsMissing(varTitleForDialog) Then

varTitleForDialog = ""

End If



'Open a file save dialog box for xls files

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", "*.XLS")

'set the initial directory to the desktop

'set the text for the title of the FileOpen dialog box

'Specify the default file name

'strFileName = default save name supplied to function as variant from
calling form

'Specify the default file extension

'set openfile = false (for save instead of open)

'Now actually call to get the file and path.

MySavePath = ahtCommonFileOpenSave( _

Filter:=strFilter, _

OpenFile:=False, _

InitialDir:="c:\documents and settings\all users\desktop",
_

DefaultExt:="xls", _

FileName:=strFileName, _

DialogTitle:="Save file", _

Flags:=ahtOFN_HIDEREADONLY)

'Debug.Print MySavePath

End Function



This function needs the code from The Access Web under the api section that
calls the standard windows file open/save dialog box.

You would put the code from the access web in a standard module.



Jeanette Cunningham
 
J

Jeanette Cunningham

Hi,
Sorry for the poor formatting in previous post, here I have made it more
readable.
Here is a function I use in my databases to get the location to save the
file to when I want to export to excel.

Public Function MySavePath(strFileName As String, _
Optional varDirectory As Variant, _
Optional varTitleForDialog As Variant) As
Variant

Dim strFilter As String
Dim strSaveFileName As String 'name to save file as
Dim strPath As String 'new file save as name
Dim lngFlags As Long
' don't bother displaying the read-only box. It'll only confuse people.
lngFlags = ahtOFN_HIDEREADONLY

If IsMissing(varDirectory) Then
varDirectory = ""
End If

If IsMissing(varTitleForDialog) Then
varTitleForDialog = ""
End If

'Open a file save dialog box for xls files
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", "*.XLS")
'set the initial directory to the desktop
'set the text for the title of the FileOpen dialog box
'Specify the default file name
'strFileName = default save name supplied to function as string from
calling form
'Specify the default file extension
'set openfile = false (for save instead of open)
'Now actually call to get the file and path.

MySavePath = ahtCommonFileOpenSave( _
Filter:=strFilter, _
OpenFile:=False, _
InitialDir:="c:\documents and settings\all users\desktop",
_
DefaultExt:="xls", _
FileName:=strFileName, _
DialogTitle:="Save file", _
Flags:=ahtOFN_HIDEREADONLY)

'Debug.Print MySavePath

End Function

This function needs the code from The Access Web under the api section that
calls the standard windows file open/save dialog box.

You would put the code from the access web in a standard module.

Jeanette Cunningham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top