Showing pdf in Access form gets stuck on initializing screen - vba

I am trying to display a pdf file in an Access form, but my code only works once. When I close the Access application and reopen it Acropdf doesn't display the pdf, it just gets stuck on this screen:
Private Sub Command1_Click()
Dim strPdfDoc As String
'Below is my source
strPdfDoc = "F:\Grifols\files\Unified Region TemplateV1_0_Budget.pdf"
'Here I am loading the pdf file with Acropdf
AcroPDF0.loadFile strPdfDoc
End Sub
I get no errors when debugging the code, but the pdf never shows.

I struggled with this issue for a long time, it was only happening when the EXE was run as Administrator.
My fix was the following:
Set EXE compile to x86 CPU
Change PDF output path to ProgramData: "C:\ProgramData(Client)(Project)"
Update code to first call "AxAcroPDF1.LoadFile(PDFfilepath)" then call "AxAcroPDF1.src = PDFfilepath"
Important: If you need to run the application on Windows Server for some reason, then the 32bit version of Crystal Runtime needs to be installed

Check that your version of Adobe Reader is up to date and replace your code with this. I was able to load the file several times, close and reopen and load again.
Private Sub Command1_Click()
Dim pdf As AcroPDF
Set pdf = Me.AcroPDF0.Object
pdf.LoadFile "F:\Grifols\files\Unified Region TemplateV1_0_Budget.pdf"
End Sub

I had Acrobat Reader DC installed, I Downgraded to 11 from this link
https://helpx.adobe.com/acrobat/kb/install-reader-x-windows.html
And changed the following registry setting to get this to work
To disable the Enable Protected Mode at startup configuration, navigate to the following registry key:
HKEY_CURRENT_USER\Software\Adobe\Acrobat Reader\DC\Privledged
… then modify the bProtectedMode REG_DWORD value to 0 to disable and 1 to enable:
found it at this link
http://terenceluk.blogspot.co.uk/2016/01/disabling-enable-protected-mode-at.html

I found a solution, that work for me, at this link:
To solve initializing screen for Acrobat Reader XI, just disable "Enable Protected Mode At Startup"

Related

How to enable Print button in PrintPreview using vba

I'm using below code inWorkbook_Open()event:
Application.Dialogs(xlDialogPrintPreview).Show
at very first time when I click on enable content then preview page is opened but Print option is disabled
That is because you are using the Legacy version of print preview.
Similar question was asked on the official Microsoft forums here
The best reply quoted here:
Hi
By deault the option for settiing print area, rows to repeat and
columns to repeat are greyed out if you display the Page Setup dialog
via the Print option. "I go to print and go to Page Setup".
I would suggest using the Print Titles button on the Page Layout tab
in the ribbon to make the neessary changes.
As you are a veteran of previous versions this greying out was the
case if you activated Page Setup from the Print Preview options but
not through File, Page Setup. In the shuffling of the user interface
from 2007 onwards, File, Print is effectively the equivalent of the
old Print Preview and the Page Setup options in the Page Layout tab
the equivalent of the "old" File Page Setup.
Hope this helps
So to sum it up
I'd probably recommend the following code instead:
Obviously may need some tweaking depending on your desired functionality. It's not clear what exactly you're trying to achieve.
Private Sub to_pagelayout()
ActiveWidow.View = xlPageLayoutView
End Sub
Produces the following result
As for switching actual ribbon tabs, I think that is best reserved for a separate question. I'll also leave the link to the official documentation here
You can alternatively use
Application.CommandBars.ExecuteMso ("PrintPreviewAndPrint")
which is the same as pressing File › Print.
Since it seems that this odd behavior only occurs when macros were disabled before:
Define "trusted locations" or digitally sign your VBA code with a trusted certificate to solve this issue. Digitally signed code or code in trusted locations is executed without any message (with the accordingly set properties in the Trust Center).
It's anyway a good idea to sign your own/company code to get rid of these messages for trusted code and make people sensitive to that message again (so that it is not clicked away carelessly).
Same strange behavior on Excel 2007.
Workaround: use Application.OnTime
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:00:00"), "PrintPreviewOnWorkbookOpen"
End Sub
And the SubPrintPreviewOnWorkbookOpen in a module
Public Sub PrintPreviewOnWorkbookOpen()
ThisWorkbook.PrintPreview
End Sub

AXAcroPDF will not load

I have a PDF COM control on a Windows Forms Application. The process is simple, a file path is sent to a Sub, it checks if the file exists and if so, loads the file on my PDF control and shows the form. The code is simple:
Public Sub LoadPDF(ByVal pathPDF As String)
MessageBox.Show(pathPDF)
If System.IO.File.Exists(pathPDF) Then
frmPDF.dePDF.LoadFile(pathPDF)
frmPDF.Show()
Else
MessageBox.Show("No image available. Please check FEMA and CAMSIS.")
frmPDF.Hide()
End If
End Sub
This code worked 2 hours ago. The same code still works in other applications (that pull the exact same file path). I have compared designer codes/control properties/etc between the current application and the others. I can't find a difference at all. I have tried completely recreating the form and COM control.
Does anyone know why this may be happening?
My solution:
The reference .dll files were corrupt. I used the solution here C# System.AccessViolationException and System.Runtime.InteropServices.SEHException
to fix it. Everything seems to be running fine for now.
Use this instead
axAcroPDF1.src = PDFPath;
To load your PDF into the control instead of LoadFile.

Error on Load Event when using My.Settings

I am currently having an issue with the usage of embedded settings in my application. I intend to use them with the form load/closing event, but I am recieving an error like this user:
Error when loading mySettings [Visual basics 2010]
I looked at my settings.vb file and everything appears to be in order, but I am not really sure what could have become incorrect/corrupt because it is all generated when I make changes to the project properties. In order to check if my usage of the settings was correct I created a new project with:
Private Sub Load()
Textbox1.Text = My.Settings.Test
End Sub
Private Sub Close()
My.Settings.Test = TextBox1.Text
End Sub
Everything is working perfectly in the new project, so the error is isolated to my particular project. Has anyone encountered this or have any ideas on how to remedy it?
Thanks for any help!
Exact Same Error from another user:
For those people googling this in the future here is the solution in my case:
Click View Detail and continue navigation through the error detail until you find the path to the app.config file. Once you find it move it to a backup location and run your app again. The file will be regenerated correctly.

Getting Startup Location In Windows

I've written a small program to open at startup, but I want to give the user the ability to delete it from showing on startup by clicking a button.
But it needs to be compatible on XP, Vista and Windows 7.
Is there a line of code which will get the default startup folder path automatically so I can then delete it using my button?
Thank you in advance
What you are wanting is the SpecialFolder.Enumeration. and use the Environment methods
Something like this Environment.GetFolderPath(Environment.SpecialFolder.Startup)
To do your deletion you need to use System.IO.File.Delete(path)
To check to see what files are out there try making a console application and use this code.
Module Module1
Sub Main()
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup)
For Each file In System.IO.Directory.GetFiles(path)
Console.WriteLine(file)
Next
Console.ReadLine()
End Sub
End Module

Help files open in two browsers

In our application, when you go to "Menu > Help...", it opens our help files in Internet Explorer, which is the desirable effect. However, we have the shortcut key "F1" set to open the help files as well. It still opens the help in Internet Explorer... but it also opens them up at the same time in the user's default web browser!
Here is the code in the event method that opens the web browser:
Private Sub menuHelpHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuHelpHelp.Click
Dim temp As String = String.Format("{0}\Internet Explorer\iexplore.exe", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles))
Dim temp2 As String = String.Format("{0}", Globals.HelpFilePath)
If Not System.IO.File.Exists(temp2)
MessageBox.Show(String.Format("Could not find index.html, run ""help_zip.exe"" inside the Doc folder as an Administrator to restore the help system (make sure to overwrite all files when asked!)"))
Else
System.Diagnostics.Process.Start(temp, temp2)
End If
End Sub
If I step through the code after clicking the Help menu item, IE opens as intended when I hit the "System.Diagnostics.Process.Start(temp, temp2)" line. However, when I do the same thing after pressing F1, it opens first in the user's default browser, and then in IE second. Any ideas? The code in this part of the application is written in VB.NET, and the application is a .NET 3.5 app.
Out of curiosity, have you tried binding the action to another button to see if the problem still exists? Switch it from F1 to F2, see if it still happens. Almost certainly will, unless there's some code in your program which you forgot about that's causing problems.
EDIT
You appear to be setting a global variable for your help path.. which means the default F1 Help would likely load the correct file. So I'd go with the "F1 is still bound to the default Help action." You'll need to unbind it.