Trying to open an image from a URL without the extention - VBA - ms-access

I am currently trying to work on a database that stores a collection of cards, and I'm trying to fetch Images from Magic's Gatherer service in order to help identify the card.
This is the code I am currently Using:
Private Sub ID_Change()
cardImage.Picture = "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=" & ID.Column(0) & "&type=card"
End Sub
cardImage is a picture object
ID is a combo box, with the first column as a Long Integer.
Now then, my issue is that access isn't liking the URL that I'm providing it, and is throwing a Run-Time error 2220. Is there any way to get access to accept the URL as a JPEG, and load it?

Instead of using an Image object, try using a Web Browser Control object and set its .ControlSource property, something like
Me.WebBrowser2.ControlSource = "=""http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=" & ID.Column(0) & "&type=card"""

Related

MS Access run time error 438 on load event

I am trying to display logo on MS Access report header. I am using table with the name of Portfolio with contain my ID, Logo fields. After upload image in this table now on report header I added the Image unbounded frame with the name of AutoImage. Now then on load event of report when i call this function it give me error.
Private Sub Report_Load()
Me.AutoImage.Picture = DLookup("[Logo]", "Portfolio", "[ID]=1")
End Sub
The erro is:
MS Access run time error 438 Object does not support this property or method.
Thanks its working now. I was using image Object Frame. This was my mistake, i just replaced Object frame with Image. Now it working.

Label Hyperlinks on MS Access 2013 Reports

I am having troubles with being able to click hyperlinks on reports in MS Access 2013. My database serves the function of a project log which tracks what projects our group is working on. The hyperlinks serve as an attachment to a summary file (usually PPT) for each project. Each project is a record in my backend table.
So far I have:
Stored the hyperlink as a string in a database table
Pull/edit/add hyperlink to a record via Access forms
Show the hyperlink and click on it via Access forms
Add the hyperlink on a report by referencing a hidden textbox which houses the path
The problem is that the hyperlink shows up on the report correctly and sometimes I am able to click on it, but the majority of the time I cannot click on it. If I scroll around the report, sometimes I can get the hyperlink active but it seems hit or miss.
Here is the code I used to apply the hyperlink on the report:
Private Sub Detail_Paint()
Dim strSource As String
If Report_rptCompleted.txtHL.Value <> "" Then
strSource = Report_rptCompleted.txtHL.Value
Report_rptCompleted.lblHL.Caption = Right(strSource, Len(strSource) - InStrRev(strSource, "\"))
Report_rptCompleted.lblHL.HyperlinkAddress = strSource
Report_rptCompleted.lblHL.ForeColor = vbBlue
Else
Report_rptCompleted.lblHL.Caption = "No Attachment"
Report_rptCompleted.lblHL.HyperlinkAddress = ""
Report_rptCompleted.lblHL.ForeColor = vbBlack
End If
End Sub
Any help on resolving this issue would be greatly appreciated
I ended up having to go a different route and use a text box instead of a label.
My solution was to drop the label and OnPaint event entirely. I formatted the textbox to show the file name then referenced the file path in the OnClick event with a FollowHyperlink command.
It is a good bit slower opening the link but works fine.

Saving Image as OLE Object, in Access

I have a table with a field that is of type OLE Object. I then have a form with a number of fields. Some are just text fields. But, I also have an Image object on the form. When a user clicks a button, a dialog opens and they can pic a photo. Once they select the photo, the Image object displays that picture. I want to save that image to database. What I have only seems to save a reference to where the file is located, on the computer. So, this would not work if the db is moved. Here is the code I have:
Dim wrkCurrent As DAO.Workspace
Dim dbs As DAO.Database
Dim rstPerson As DAO.Recordset
Set wrkCurrent = DBEngine.Workspaces(0)
Set dbs = CurrentDb
Set rstPerson = dbs.OpenRecordset("SELECT * FROM tbl_person WHERE id =" & ID)
With rstPerson
.Edit
!bio_photo = Me.Image37.picture
.Update
End With
How would I save the image file to the OLE Field, so that I could load it back to the Image object, on the form, at a later time?
Thanks
Answer:
So, what I ended up doing was following this https://support.microsoft.com/en-us/kb/210486 [EDIT: that link is now dead, try this instead]
I use the readBLOB function to read the file and save it into the database. Then, when I run a report or open a form that has the picture, onload, I use the WriteBlob function to write the file to a temp folder and then use that path to populate an Image object.
Databases can grow to enormous sizes when you start embedding images, leading to slower queries, crashes, timeouts, and dissatisfied users. Use OLE with caution when adding images into a database
Simple Google search has how to load ole object from folder into table
And a search on this site comes up with auto attach images using vba

Dynamically filling a dropdown box in a web page using an Excel sheet with VBA

I have an Excel sheet say A that contains a list from A1 to A75 that has to be dynamically replace the value in a webpage that contains a drop down list.
For each and every replacement value it needs to pull the report from the web page and save that to an Excel sheet B.
All of this function has to happen by clicking a form control button in Excel.
Please suggest & post the code if any.
I'm new to VBA and Excel; I’ve been instructed to get the values of currencies across the world with other currencies. This has to be done 365 days.
Although I’ve suggested to try with Macro in order to pull the data from webpage to excel, but after viewing the site i came to know that each and every currency has to be selected from the dropdown list and need to export those currencies to an excel file.
This becomes a hectic issue, so i thought of a solution and come up with an idea (I'm not sure whether this gonna work or not) and posted here to seek assistance for this issue.
//
Further assistance to the question, Excel file contains more than 75 currencies and those currencies need to be selected with the System date and need to select the Currency code starting from "AED" to "ZWD", for each entry need to export the file to excel. There is an option available for that in that webpage.
//
Hope this clarifies your requirement, for further assistance please let me know !
Best Regards,Pravin
it's hard if you don't have good VBA and HTML knowledge.
in general you can do this by using a http request object instead of the IE automation. This is faster and from my point of view also easier:
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", "http://www.cboden.de"
oRequest.Send
MsgBox oRequest.ResponseText
If you are behind a proxy you can use something like this:
Const HTTPREQUEST_PROXYSETTING_PROXY = 2
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.setProxy HTTPREQUEST_PROXYSETTING_PROXY, "http://proxy.intern:8080"
oRequest.Open "GET", "http://www.cboden.de"
oRequest.Send
MsgBox oRequest.ResponseText
and if you want to use POST (instead of the GET method) to pass some values to the webserver, you can try this:
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "POST", "http://www.cboden.de/misc/posttest.php"
oRequest.SetRequestHeader "Content-Typ", "application/x-www-form-urlencoded"
oRequest.Send "var1=123&anothervar=test"
MsgBox oRequest.ResponseText
if you put it into a function then you can use it in you worksheet:
Function getCustomHyperlink(ByVal pURL As String) As String
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", pURL
oRequest.Send
getCustomHyperlink = oRequest.ResponseText
End Function
within the worksheet you can then say for example:
=getCustomHyperlink("https://www.google.com/search?q=" & A1 )
if your search value is in A1
If you have to use the GET or the POST method depends on the website you want to retrieve.
1 In Excel IDE, add reference to "C:\Windows\System32\ieframe.dll".
(Press F11 excel to go to IDE) (Tools | Reference | Browse | locate the above file )
2 Create a module with following code and run it. It will open the IE and go the yahoo site
Sub aa()
Dim aa As New SHDocVw.InternetExplorer
aa.Visible = True
aa.Navigate "http://www.yahoo.com.hk"
Stop
End Sub
3 Complete the above program by this idea:
Excel program is emulating a user navigation to the required web page.
The program waits the page is completely loaded. Then read the page content by aa.document.
Write the required data from aa.document into an excel worksheet.
Repeat.

Can I use a variable as the name of a control in Microsoft Access VBA

I have a Microsoft Access Popup Form which I use to lookup addresses. Once the user has found the postcode, the address is then put into various text boxes on the form it was launched from. The problem is, this popup form is launched from various forms throughout the database and so the text boxes it puts the result into are in different locations.
I tried to work around this in the following way. I have a switchboard which is open at all times so I have a hidden Textbox on there which I programmatically put the name of the form I am launching the popup form from. I then declare a string variable which is set to the current value of this hidden textbox like so:
Dim currentForm As String
currentForm = [Forms]![foo]![bar]
I then tried to put my address details into the relevant textboxes like so:
Forms!currentForm![txtCurrentAdd1] = rst![Line1]
However this isn't working as planned, what am I doing wrong?
Thanks
Either:
Dim currentForm As String
''Not sure where the two parts are coming from
''but you cannot have them like that
currentForm = "foobar"
Forms(currentForm).[txtCurrentAdd1] = rst![Line1]
Or
Dim currentForm As Form
Set currentForm = Forms![foobar]
currentForm![txtCurrentAdd1] = rst![Line1]
You might like to read up on bang vs dot.
Mind you, the whole thing looks a little like you are swimming upstream.
You can access controls on other forms like this:
Dim FormName As String
Dim ControlName As String
FormName = "YourForm"
ControlName = "YourTextbox"
Forms(FormName).Controls(ControlName) = "New Value"
You could also use the OpenArgs property. To open your reusable popup, use:
DoCmd.OpenForm FormName:="frmPopup", OpenArgs:=Me.Name
in order to pass the caller's name.
In the frmPopup, you can refer to Me.OpenArgs to get that information.
I know this is an old post but this might be useful for new readers. The simple way I get round the problem of passing variables between modules and forms is to use the VBA registry area. It's a very simple and easy to use technique and keeps projects nice and clean.
To save a value:
SaveSetting AppName, Section, Key, Setting
To get the value:
GetSetting AppName, Section, Key, [Default]
This avoids loosing track of variables and creating hidden controls on forms. It also works cross platform without change on a PC and a Mac.
I then usually set a load of constants in my projects to define the first three parameters:
Public Const REG_PROD = "My product name"
Public Const REG_CONFIG = "Configuration"
Public Const REG_SETTING1 = "My Setting 1"
So the above calls would become:
To save a value:
SaveSetting REG_PROD, REG_CONFIG, REG_SETTING1, "My Value"
To get the value:
GetSetting REG_PROD, REG_CONFIG, REG_SETTING1, "Value not set"
I used to use the hidden control method but it adds a lot of management and you can't always the variable values whereas you can keep an instance of RegEdit open for debugging purposes.
I think
Me.Controls(variablelabelName).Caption
you can write code to make the variable change and use as the label's name to create the unique caption for each label.