Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
VBA code not running On Open
Dean Brodie 

2 years ago
I am attempting to open a pop up form to display a given PDF file using a command button on a subform of the main form. The pop up form opens but with the message "Can't reach this page". I have tried the code in both Open and Load with no success. However when I run the same code from a command button on the pop up form the correct PDF file does open. See the code below. Any ideas?

Private Sub Command2_Click()
Dim filePath As String
filePath = "C:\Users\drbro\OneDrive\Documents\Access\DSM D number scans\" & [Forms]![frmMain]![Child44].[Form]![PDFnum] & ".pdf"

Me.WebBrowser1.Object.Navigate filePath
End Sub

Private Sub Form_Load()
Dim filePath As String
filePath = "C:\Users\drbro\OneDrive\Documents\Access\DSM D number scans\" & [Forms]![frmMain]![Child44].[Form]![PDFnum] & ".pdf"

Me.WebBrowser1.Object.Navigate filePath

End Sub

Private Sub Form_Open(Cancel As Integer)
Dim filePath As String
filePath = "C:\Users\drbro\OneDrive\Documents\Access\DSM D number scans\" & [Forms]![frmMain]![Child44].[Form]![PDFnum] & ".pdf"

Me.WebBrowser1.Object.Navigate filePath

End Sub

Richard Rost  @Reply  
          
2 years ago
Could be a timing issue. A lot of things don't run well in the Open/Load events. Try using a Timer event instead.

See: Load Faster
Dean Brodie OP  @Reply  

2 years ago
Thanks Richard,
That sounds about right - I will try your suggestion.
Dean
Dean Brodie OP  @Reply  

2 years ago
I ended up adding Wait For (1) before the VBA code in Load and it worked. Thanks for your help!

Sub WaitFor(NumOfSeconds As Long)
Dim SngSec As Long
SngSec = Timer + NumOfSeconds

Do While Timer < SngSec
DoEvents
Loop

End Sub
Richard Rost  @Reply  
          
2 years ago
That's another way to do it. :)

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/2/2026 3:45:28 AM. PLT: 1s