Solved

Access Web Browser - copy contents

Posted on 2013-01-29
8
250 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
ID: 38832069
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
ID: 38832559
Looks perfect, will need to test it put tomorrow when I'm back at my PC.
0
 

Author Comment

by:correlate
ID: 38834597
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 39

Expert Comment

by:als315
ID: 38834676
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
 

Author Comment

by:correlate
ID: 38834726
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
ID: 38834740
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
ID: 38834985
In your case you need declare function as Public
DBWeb1.accdb
0
 

Author Closing Comment

by:correlate
ID: 38836070
Brilliant - thank you very much - it works a treat!
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ms Access VBA Variables 6 28
Question about DB Schema 27 56
Why get error when delete all records on a sub-form 2 16
combo box query 6 8
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

777 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