Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.OpenReport Hangs when user wants to select location of report to save to

Status
Not open for further replies.

Jaime_78

Programmer
Jan 26, 2022
2
0
0
SG
Hi
I am new to this forum and also to vba programming. I need help urgently.

Have developed a program using MS Access. It was working well until lately my machine was upgraded with Office 360.

Somehow when I try to print report with the code below, the command window will open to prompt user to select a location to save the report, and after that it hangs....and I have to kill the task through task manager.

'string value to pass in to the report in Ms Access.
strCriteriaToRpt = "7372Z"
DoCmd.OpenReport "View Remarks of Students", acViewNormal, , strCriteriaToRpt

However, if I were to change the program to the code below, the user will not be allowed to choose the location to save the report, but instead system will save the report to the location that I have specified. And the program works fine.

DoCmd.OpenReport "View Remarks of Students", acViewPreview, , strCriteriaToRpt
MyPath = "D:\SIS\Report_" & strStudentID & ".pdf"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, MyPath, False

Can someone enlightened me how I can resolve the problem above? Appreciate.
 
Have you considered:

Code:
Private Sub Whatever()
...
DoCmd.OpenReport "View Remarks of Students", acViewPreview, , strCriteriaToRpt
MyPath = [blue]GetFolder & "\Report_" & strStudentID & ".pdf"[/blue]
DoCmd.OutputTo acOutputReport, "", acFormatPDF, MyPath, False
...
End Sub
[blue]
Function GetFolder() As String
    Dim fldr As FileDialog
    Dim sItem As String
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
    With fldr
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = Application.DefaultFilePath
        If .Show <> -1 Then GoTo NextCode
        sItem = .SelectedItems(1)
    End With
NextCode:
    GetFolder = sItem
    Set fldr = Nothing
End Function[/blue]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Thank you so much Andy, I'll give it a try. Appreciate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top