Link to home
Start Free TrialLog in
Avatar of MCaliebe
MCaliebeFlag for United States of America

asked on

Resolve Web Address error in SQL

I am attempting to access images on a server.  The address are all in the same string format, however one piece of the address could be upper case or lower case

Example: http://webaddress/image/12345AN.gif might be
http://webaddress/image/12345AN.gif or might be http://webaddress/image/12345an.gif

Is there a way through VBA to evaluate the first address, and if it returns the 403 Error, than to use the second address?
Avatar of arnold
arnold
Flag of United States of America image

You have to perform the request and check the response status, then query for the other.
Http_tequest.  Not sure how your question dealing with SQL.

A web you would use a client side script to load the image in the background and display the one you can retrieve.
Though not sure why you would want the overhead is the image being loaded from a different source than the server from which this content is being served?

If the remote site allows directory browsing, you can look at the image folder and use the proper name they have there.  It might have been switched to jpg. JPEG, png because of gif limitations, implications.
Avatar of MCaliebe

ASKER

What I'm doing is using a MS Access DB form to view properties of different items.  I don't have local copies of the images which correspond to the data I'm working with, so I set up a picture control on my form to get the picture from the web when I pull up the item.

Sometimes the weblink generated is correct, other times it is not.  It always appears to be a formatting issues- Upper and Lower case.  I was hoping to test the first link, if a picture is there, use it, if not, move onto the next possible formatted web link and use it.
Instead of attempting to retrieve, you can issue a Request for the header of the data you wish to retrieve, and you will need only to handle the response to determine if the file is there, 2xx response. 3xx means the location changed, which means you need to look at the location: from the response to determine where it moved to.
If you get 4xx or 5xx means there is an issue first file not there or is inaccessible, the other server ran into a situation and can not respond,......
I've not played with much related to web request and responses.  Can you elaborate on how this might be done or direct me to where I might find examples?
Here is a link, http://tkang.blogspot.com/2010/09/sending-http-post-request-with-vba.html
In the suggestion, you would use HEAD as the request not POST nor GET.
Would this be correct?  It is moving through the code fine, however I never see any "Result"

Public Function WebHeadRequest(MyURL)

Dim result As String
Dim winHttpReq As Object
Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")


winHttpReq.Open "HEAD", MyURL, False
winHttpReq.Send
result = winHttpReq.responseText
Debug.Print result

End Function
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked.  I was able to get a response like "200" or "403" and work with these responses.

winHttpReq.Open "GET", MyURL, False
winHttpReq.Send
result = winHttpReq.Status
WebHeadRequest = result
Use HEAD instead of Get.  You get the same status header response without the overhead of retrieving data unnecessarily.
Got it!  Thanks!