Solved

Access Web Browser - copy contents

Posted on 2013-01-29
8
247 Views
Last Modified: 2013-01-30
Dear Experts

I have a form with a built in WebBrowser ("WebBrowser3") - this displays a QR code (a vCard) which has been generated from various fields in the data base.  What is displayed is a .png picture which has been generated from http://chart.apis.google.com

What I'd like to do is write a piece of code that copies that picture and saves it to my desktop - in effect the same as doing the following ... Right Click on the webbrowser & "Save Picture as"

Can anybody help?
0
Comment
Question by:correlate
  • 5
  • 3
8 Comments
 
LVL 39

Expert Comment

by:als315
Comment Utility
I think you can do it in two steps:
1. Find picture's url. Sample you can find here:
http://www.vbforums.com/showthread.php?384076-Webbrowser-Control-Tip-and-Examples
2. Download it and save with UrlDowndoadToFile:
http://stackoverflow.com/questions/12269941/vba-urldownloadtofile-data-missing-in-downloaded-file
0
 

Author Comment

by:correlate
Comment Utility
Looks perfect, will need to test it put tomorrow when I'm back at my PC.
0
 

Author Comment

by:correlate
Comment Utility
Hi Thanks for this, alas I cant get it to work & I get an error pointing to this line:

   Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)

The code I have is as follows:

In the form:
Public Sub DownloadMeFile_Click()
  
Dim QRString As String
Dim QRString1 As String
Dim QRString2 As String

QRString1 = "http://chart.apis.google.com/chart?cht=qr&chs=350x350&chld=L&choe=UTF-8&chl=BEGIN%3AVCARD%0AN%3A"
QRString2 = Me.[Gen-FullName] & "%0AORG%3AArcus Global Partners%0ATITLE%3A" & Me.[Gen-JobTitle] & "%0ATEL%3A" & Me.[Card-QRPhoneUsed] & "%0AURL%3A" & Me.[Card-URL] & "%0AEMAIL%3A" & Me.[Gen-WorkEmail] & "%0AADR%3A" & Me.[Card-QROffice Address] & "%0ANOTE%3A" & Me.[Card-QRNote] & "%0AEND%3AVCARD"
QRString2 = Replace(Replace(QRString2, "+44 (0)", "0"), " ", "+")
QRString2 = Replace(Replace(QRString2, "@", "%40"), "/", "%2F")
QRString2 = Replace(Replace(QRString2, ":", "%3a"), "/", "%2F")
QRString = QRString1 & QRString2

  
Dim strURL As String
    Dim strPath As String

    strURL = QRString

    strPath = "C:\Users\tcrowfoot\Desktop\test.png"

    Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)

    If Ret = 0 Then
        MsgBox "File successfully downloaded"
    Else
        MsgBox "Unable to download the file"
    End If

End Sub

Open in new window


In a Module
Option Explicit

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

Dim Ret As Long

Open in new window


These are the full codes, so not sure if im being thick / missing anything
0
 
LVL 39

Expert Comment

by:als315
Comment Utility
I can't test you real picture, but file EE logo is downloaded without problems. Look at sample. Declaration was modified for 64 bit and 32 bit os.
DBWeb1.accdb
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:correlate
Comment Utility
Hi

Many thanks for this,

I added a form to your sample to fire it up from & unfortunately I'm still getting the same error message: "Sub or Function not defined" pointing to Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)

My pc is 64bit

I have attached my version of your sample, would you be able to take a look at it?
DBWeb1.accdb
0
 

Author Comment

by:correlate
Comment Utility
Hi

Just spotted that i was missing the URL, have out that back in, but alas still get the same problems - new version attached
DBWeb1.accdb
0
 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
Comment Utility
In your case you need declare function as Public
DBWeb1.accdb
0
 

Author Closing Comment

by:correlate
Comment Utility
Brilliant - thank you very much - it works a treat!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now