Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / April 2008

Tip: Looking for answers? Try searching our database.

Read text from .txt file via hyperlink

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bravofoxtrotuk - 24 Apr 2008 11:08 GMT
This seemed easy at first...
I have a database which users can download from a web site in a zipped file,
and then use on their machines - completely free-standing.  

How can I get the database to go to a .txt file on the website when it
opens, read the text (which will be one line consisting of the latest version
number which I will put in there), then read the version number and compare
it with the version of the database they are running?  This is so that I can
put up a message saying "New version is available".

I've tried FollowHyperlink and OpenTextFile, but can't quite get to read the
text from the file.
Stuart McCall - 24 Apr 2008 11:38 GMT
> This seemed easy at first...
> I have a database which users can download from a web site in a zipped
[quoted text clipped - 13 lines]
> the
> text from the file.

Dim f As Integer
Dim buffer as string

f = FreeFile()
Open "Filename.txt" For Binary Access Read As f
buffer = Space$(LOF(f))
Get #f, , buffer
Close f

The string variable buffer will then contain the whole contents of
Filename.txt, which you can then use for your comparison.

Tip: When you create or update your text file, just type the version info
and don't press Return. This will save you having to remove the
carriage-return/linefeed in your comparison code.
bravofoxtrotuk - 24 Apr 2008 12:12 GMT
> > This seemed easy at first...
> > I have a database which users can download from a web site in a zipped
[quoted text clipped - 29 lines]
> and don't press Return. This will save you having to remove the
> carriage-return/linefeed in your comparison code.

Stuart,
thanks for quick reply, but I'm getting the same error message as in my
previous messing about - "run time error 52, bad file name or number".  I'm
using "http://website.net/test.txt" for the filename so I guess it's that, as
the f variable is fine.
If I use IE it opens the file with that address OK.
Bob
Stuart McCall - 24 Apr 2008 15:09 GMT
>> > This seemed easy at first...
>> > I have a database which users can download from a web site in a zipped
[quoted text clipped - 41 lines]
> If I use IE it opens the file with that address OK.
> Bob

Yes that's the problem. You're trying to use a URL as a filename. Web
servers require that you use relative paths. If the text file resides in the
same folder as your database file then use just the filename, ie:

Open "test.txt" For Binary Access Read As f

or, failing that:

Open "./test.txt" For Binary Access Read As f

If the file resides elsewhere, you need to bone up on relative paths. You're
sure to turn up something on Google...
bravofoxtrotuk - 25 Apr 2008 07:17 GMT
> >> > This seemed easy at first...
> >> > I have a database which users can download from a web site in a zipped
[quoted text clipped - 54 lines]
> If the file resides elsewhere, you need to bone up on relative paths. You're
> sure to turn up something on Google...

Hi Stuart,
well, as the file's on a remote web server it would need to be an absolute
reference. However, many hours further research reveals that Open can't be
used with ftp or http, but elsewhere on the forum in an old thread, Doug
Steele has once again come up with an answer.  I've copied the reference
below:

[ See whether what I wrote about in my November, 2003 "Access Answers" column
for Pinnacle Publication's "Smart Access" has what you need.

You can download the column (and accompanying sample database) for free at
http://www.accessmvp.com/djsteele/SmartAccess.html ]

There's also info in there about extracting what you want from the html
which is returned.  In my case I don't need that as I'm getting data from a
plain .txt file which consists of just text (actually, a number).  As I'm the
one putting the file there, I can be sure of the format.

This is the code of Doug's I've tested in case anyone else is struggling
with this:

Function GetFromWebpage(URL As String) As String
On Error GoTo Err_GetFromWebpage
Dim objWeb As Object
Dim strXML As String
' Instantiate an instance of the web object
Set objWeb = CreateObject("Microsoft.XMLHTTP")
' Pass the URL to the web object, and send the request
objWeb.Open "GET", URL, False
objWeb.Send
' Look at the HTML string returned
strXML = objWeb.responseText
GetFromWebpage = strXML
Debug.Print GetFromWebpage
End_GetFromWebpage:
' Clean up after ourselves!
Set objWeb = Nothing
Exit Function
Err_GetFromWebpage:
' Just in case there's an error!
MsgBox Err.Description & " (" & Err.number & ")"
Resume End_GetFromWebpage
End Function

So using my example from earlier in this post:

GetFromWebpage "http://website.net/test.txt"

- returns my text (number)  - I just need to sort out what I do with it now...

Bob
Stuart McCall - 25 Apr 2008 08:37 GMT
>> >> > This seemed easy at first...
>> >> > I have a database which users can download from a web site in a
[quoted text clipped - 118 lines]
>
> Bob

Yes that's the correct way to get the text. Sorry for leading you astray
(don't know what I was thinking). Incidentally, there's another method,
similar to Doug's that uses InternetReadFile from wininet.dll:

http://www.smccall.demon.co.uk/MiscApi.htm#Scrape

(purely out of interest, being as you have a solution)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.