Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2011
    Posts
    29

    Unanswered: Can access check for a file on the Internet

    Can Access check for the existence of a file on the Internet?
    Thanks,
    John

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you probably need to use some form of xml/json process
    try VBA web services
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Sep 2011
    Posts
    29
    Thanks for the reply. I will look into your suggestion.

    If it helps I can check for a URL using the following code:

    Private Sub btnCheck()
    Dim blnDum As Boolean
    blnDum = blnURLExists("http://www.visualdentist.com")
    ' blnDum = true if it exists, it is = false if it does not
    End Sub

    Public Function blnURLExists(ByVal strURL As String) As Boolean
    Const FLAG_ICC_FORCE_CONNECTION As Long = &H1

    blnURLExists = (InternetCheckConnection(strURL, FLAG_ICC_FORCE_CONNECTION, 0&) <> 0&)

    End Function


    Does this help at all?
    John

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    i dunno
    why not try it and see for yourself?
    bearing in mind that a resource on an internet is identified by its fully qualified URL
    eg:-
    http://www.mywebsite.com/my/path/to/a/file.txt
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Sep 2011
    Posts
    29
    I did try it before and it looks at the URL and not at the file. In other words if the file does not exist and the Web page URL exists, it returns True.
    John

  6. #6
    Join Date
    Sep 2011
    Posts
    29
    The following seems to work, but needs addition of the "Microsoft XML v6.0" reference.

    On Error GoTo ErrorHandler
    Dim httpReq As MSXML2.XMLHTTP60
    Set httpReq = New MSXML2.XMLHTTP60
    httpReq.Open "GET", "http://www.Microsoft.com/FolderName/FileName", False
    httpReq.send
    If httpReq.Status = 200 Then
    MsgBox "Resource found"
    Else
    MsgBox "Not found"
    End If
    Exit Sub
    ErrorHandler:
    MsgBox "unexpected error"

  7. #7
    Join Date
    Sep 2011
    Posts
    29
    I have spent a lot of time on the MSXML2.XMLHTTP60, which can be handled with late binding which avoids the need for a Reference.

    After searching half the Internet and lots of testing MSXML2.XMLHTTP60 is not to be trusted fully. Other users have flagged problems that exist and my testing confirms this. Maybe in my case my params were wrong.

    Anyway I believe that API URLDownloadToFile is a better option. So far it has been behaving and would be interested to hear whether you had any experience with this API. If there is interest I can post the code.

    John

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Sorry i dont understand your comment in post #5.
    If you specify a resource using a fully qualified URL and the server responds appropriately then tbe file exists. If the response is 4xx then the resource doesnt exist. There can be no confusion a URL is a pointer to a location of a file.
    The only scope for error is if the webserver interprets that request as an html document.
    The problem is that you specified a server NOT a file.your code in post #2 didnt specify a file, it requested the main page of the website.
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Sep 2011
    Posts
    29
    After trying many things I would like to share my experience. The solution depends on what you want to achieve. In my case I wanted Access to check whether a specific file (whose name I know) exists in a folder in a specific Web site. If the Web site Microsoft.com has a folder called “UserFiles” and this folder contains a file called “abc.jpg”, then my goal was to check for the presence of

    http://www.Microsoft.com/UserFiles/abc.jpg

    For the inquisitive, the presence or absence of a specific file, may cause the application to take certain actions like quitting the application.

    1) At the end of the day I used the following. The original problems which I experienced were due to the fact that I was trying to cut corners while in Debug mode.
    Code:
    Public Function fblnCheckSerial(strSerial As String) As Boolean
    On Error GoTo ErrorHandler
    Dim httpReq As Object     
    Set httpReq = CreateObject("MSXML2.ServerXMLHTTP")
    httpReq.Open "GET", "http://www.Microsoft.com/UserFiles/abc.jpg", False
    httpReq.send
    If httpReq.Status = 404 Then     ‘File not present
        fblnCheckSerial = False
    Else
        fblnCheckSerial = True
    End If
    Exit Function
    ErrorHandler:
    MsgBox "unexpected error"
    
    End Function
    Caveat: A large number of web applications uses dynamic web URL and thus may resolve a URL that points to non-existent file to a valid page and you'd fail to download the file or at least get unexpected result when you download "something" from that URL. In my case this is not a problem.

    2) You could use the following API, if you need to download a file (not needed in my case) and thus check for the existence of the file.
    Code:
    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
    For an in-depth example please look at
    Downloading A File

    Hope this helps,
    John

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •