Question

Navigate web dialog from Access and execute file Save

Asked by: NashVegas

I modified some code provided by ChuckWood to open a URL using VBA from Access. If I click on this URL, IE opens and a Open/Save/Cancel dialog displays. I can press the tab key 3 times to set focus on the Save Key and press enter to open a Save dialog. When I try to duplicate this with "SendKeys", it does not work. Is there a better way to go about this?

Public Function OpenIe(ByVal strLocation As String)
    Dim IE As Object
    Dim dblPause As Double
    Set IE = CreateObject("InternetExplorer.Application")
 
    IE.Visible = True
'Open URL
    IE.navigate strLocation
'Wait 10 seconds for the save dialog to appear
    dblPause = Timer
    
    While Timer < dblPause + 10
        DoEvents
    Wend
'Tab 3 times to navigate to the Save button and then Enter
    SendKeys "{Tab}"
    SendKeys "{Tab}"
    SendKeys "{Tab}"
    SendKeys "{Enter}"
    
   
End Function

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-03 at 11:36:25ID24705586
Tags

Access

,

VBA

Topics

Access Coding/Macros

,

Microsoft Access Database

,

Web APIs

Participating Experts
1
Points
500
Comments
11

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. dialog focus
    hi experts. i have a an applet, that pops up a Dialog when ever the user has to put in some details. i want that the focus will not leave the Dialog untill the user conferms or cancels. if its possible i would like to lock the hole browser actually. my dialog implements focus...
  2. Implementation of OK/Cancel dialog in VBA
    Hi, In an Excel VBA macro, I have to show a custom dialog box (userform) to retrieve some data from the user. The dialog contains several editbox fields, a OK button and a Cancel button. The dialog box can be validated (OK button or ENTER) or cancelled (Cancel button o...
  3. Implementation of OK/Cancel dialog in VBA
    Hi, In an Excel VBA macro, I have to show a custom dialog box (userform) to retrieve some data from the user. The dialog contains several editbox fields, a OK button and a Cancel button. The dialog box can be validated (OK button or ENTER) or cancelled (Cancel button o...
  4. Focus of Dialog
    I have a dialog form in my MDI application. Some time if i open this dialog and run some other application then i get back to my application focus should be on this dialog form but it does not happen. This problem occurs 30 in 100 times. I tried to solve it by setting the ow...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: NashVegasPosted on 2009-09-03 at 16:54:02ID: 25256036

Anyone?

 

by: SudonimPosted on 2009-09-04 at 01:07:46ID: 25257560

is it because the sendkeys would effect the IE standard page not the open/save dialog which is opened as modal?

Maybe there is some way to handle the modal dialogue form...?

I don't know how, but perhaps there is some other way... if its just opening the webpage to save...could you use ftp to connect to the server and collect the file instead?  or some way to "GET" the http page rather thna browse and save it?

 

by: SudonimPosted on 2009-09-04 at 01:13:55ID: 25257581

ooh ooh, check this out:  thee is an API call to make get IE to save a webpage

http://www.xtremevbtalk.com/showthread.php?t=16955

IE.ExecWB OLECMDID_SAVEAS, LECMDEXECOPT_DODEFAULT

hope this helps...

i'd need to know the value o strLocation in order to try and test it for you.

 

by: NashVegasPosted on 2009-09-04 at 06:22:50ID: 25259351

Thanks for the suggestion. I'll look into it this morning. But just to be clear, I'm not trying to save a web page, I'm trying to downlaod a text document. I can't provide the link because the txt file is confidential. To help communicate this, I am attaching a screen capture. I entered the URL from my home page (google) and you see the dialog that pops up while the web page is loading. My browser never navigates away from Google, it just presents the dialog and I can save the file.

 

by: SudonimPosted on 2009-09-04 at 06:50:41ID: 25259638

Might be easier to see if you can get it from an ftp server from the provider....

then you can use shell to call a batch file to ftp the file to a local area... then link to is or import it using access VBA automation...

batch file says:
ftp -n -s:ftp.txt

ftp.txt contains:
open <server name>
user
<username>
<password>
prompt
mget *.csv (<filename> or wildcard)
quit

depends if your provider will let you ftp...

if there is no password on the file... can you try to link to it using access or excel as a linked table? presumably once you have logged in to the client area?

 

by: SudonimPosted on 2009-09-04 at 07:00:59ID: 25259742

did some research borrowed this from http://www.mrexcel.com/forum/showthread.php?t=67123 - this dude knows his stuff:

Colo
MrExcel MVP

this is in a form under a button:

see attached mdb for sample i converted his code to remove excel references and to run in access...maybe you can change the url to your file....

if you need to login to the website first it might pose a problem...

Option Compare Database
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
  "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
    szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
  
Private Sub Command0_Click()
DownloadFilefromWeb
End Sub
 
 
Sub DownloadFilefromWeb()
    Dim strSavePath As String
    Dim URL As String, ext As String
    Dim buf, ret As Long
    URL = "http://chaoticage.com/age_51.shtml"
    buf = Split(URL, ".")
    ext = buf(UBound(buf))
    strSavePath = "C:\" & "DownloadedFile." & ext
    ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)
    If ret = 0 Then
        MsgBox "Download has been succeed!"
    Else
        MsgBox "Error"
    End If
End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:

Select allOpen in new window

  • db4.mdb
    • 116 KB

    form1 - command0 code as above

 

by: NashVegasPosted on 2009-09-04 at 08:05:32ID: 25260377

Sudonim,

What this code does is download the shtml document. It navigates to "http://chaoticage.com/age_51.shtml" and saves this web page as "DownloadedFile.shtml". The URL I am using is not a link to an html document. It is a link that executes an asp script that presents the user with the Save dialog to download a specific txt file. The URL does not end in ".htm" or ".html" or ".shtml". It ends in "-08C7CC2383B58299". At this point, I do not know if I can get access to this file via ftp from the vendor. I am just working with what my internal customer has given me to work with. So I am hoping to find a way to interact with the form that opens from the URL. Is there a better zone for this question?

 

by: SudonimPosted on 2009-09-04 at 08:12:56ID: 25260451

then no.  

If you had explained the asp on-the-fly aspect in the first place i would not have wasted both our time trying to find solutions to your problem.

I edited the code to pull down the shtml file, it would work equally with a csv/xls/html/txt etc file on a web server... or any file type, and save it whever you want.

i do not think its possible to do what you want as it stands...I certainly do not know of a way to take control of the file save dialogue box which IE calls when it tries to save the file.

If the vendor can change the asp routine to create a file on the server then you can use the above to collect the created file.

Hopefully someone will come along who can find a way to automate the click to save in the dialog.

 

by: SudonimPosted on 2009-09-04 at 08:15:51ID: 25260476

have a look here:
http://www.xtremevbtalk.com/archive/index.php/t-149961.html

seems to be an API to find a windo and specify where to sendkeys to...might be usable.

 

by: NashVegasPosted on 2009-09-04 at 13:36:40ID: 25263139

Sudonim, thanks for all of your effort. I apologize that I did not explain the situation very well. I thought I had made it clear that I was not trying to save the web page, but trying to interact with the file download dialog. In my original question I said "If I click on this URL, IE opens and an Open/Save/Cancel dialog displays." And in my first follow up, I said "But just to be clear, I'm not trying to save a web page, I'm trying to downlaod a text document." then provided screenshots that illustrate how the browser does not open to a web page but only presents the dialog. I hate that you wasted your time.

I've spent a good deal of time with the last link you provided. I'm getting closer. This link has also been helpful: http://vba-corner.livejournal.com/4623.html.  I've been able to get sendkeys to work, but not reliably. Anyway, I'll close this for now and when I get a little closer I may revise the question.

 

by: SudonimPosted on 2009-09-07 at 02:05:34ID: 25273625

glad to have been able to help a little bit.

that page looks useful...

it will be more robust if you can get the 3rd party to run their asp page and store the file somewhere, on thei web server or an ftp server, so you can use one of the other methods to capture the data... that sendkeys thing is, as you have found, a bit 'ropey' to manage in IE.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...