Is it possible to open a hyperlink and display the data in a label or text box?

I have a table in Access where the data type of a record is a hyperlink. I would like to open that hyperlink and display the data in a label or text box.

It is for a school project and so quick responses would really be appreciated. I'm also sorry as this is my second thread on the matter, but no one replied to the last thread. Hopefully you can understand the urgency.

Thank you
Daniel.

no. its actually a text file.
hmmm...its hard to explain!
the user inputs the directory they would like to save the text file, the program saves that directory in access as a hyperlink. then, the user can access the file through the hyperlink?
..is it possible?!

s. u can use the file system object and textstream to open a textfile, read the data and display it in a lable or a textbox.

Add the Microsoft Scripting Runtime in the References. Create objects of the following.
FileSystemObject and TextStream


Try out these, if u still cant make the code then 'll be there to help u out.

Regards
Shaik Akthar

thank you soo much shaik for your time and help!...but i'm still unsure on how to open the text file from the hyperlink in my access database?....

cheers
Daniel

Open the recordset. Extract the field with hyperlink and connect it to the File System Object and TextStream

Dim rs as New ADODB.Recordset
Dim FSO As New FileSystemObject
Dim FL As TextStream

rs.Open "SELECT hLinkField FROM MYTABLE WHERE ID = 1", con,adopenKeySet, adLockReadOnly

'If record found then
If rs.BOF = False Then
  'open the file in the field which contains
  'the hyperlink to the textfile
 Set FL=FSO.OpenTextFile(rs!hLinkField, & _
            ForReading, False)
 Text1.Text = ""
 While Not FL.AtEndOfStream
  Text1.Text = Text1.Text & FL.ReadLine
 Wend
 FL.Close
End If

Set FL = Nothing
Set FSO = Nothing

Regards
Shaik Akthar

Here I assume u know how to connect to your database. i have considered ADODB.Connection object "con" which is global and already attached to the database.

Regards
Shaik Akthar

thank you shaik, i used that code but it says there is a complie error: User-defined type not defined...with
fso As New FileSystemObject highlighted

???

Here I assume u know how to connect to your database. i have considered ADODB.Connection object "con" which is global and already attached to the database.

Regards
Shaik Akthar

um...to connect my database...
Set db = OpenDatabase(App.Path & "\database.mdb")
Set rst = db.OpenRecordset("table")

sorry...i forgot to add the reference. but now an error message comes up saying
Run-Time error 438:
Object does not support this property or method with
rst.Open "SELECT hLinkField....." highlighted.
so, i don't know what to do!

???

cheers
Daniel

Run-Time error 438:
Object does not support this property or method with
rst.Open "SELECT hLinkField....." highlighted.
so, i don't know what to do!


Dear Dan,

I added a dummy SQL Query stating that u have to use your fieldname which has the hyperlink and table name which holds the hyperlink column.

replace hLinkField with the fieldname in your table
replace MyTable with the tablename in your database
if any filtering is to be done based on a particular column add the 'where' clause
or just query all the records like "Select * from table"


Regards
Shaik Akthar

Dim FSO As New FileSystemObject
Dim FL as TextStream

Set db = OpenDatabase(App.Path & "\database.mdb")
Set rst = db.OpenRecordset("table") 

'If record found then
If rst.BOF = False Then
  'open the file in the field which contains
  'the hyperlink to the textfile
  'here replace the hLinkField with the hyperlink field actually
  'in ur table

 Set FL=FSO.OpenTextFile(rst!hLinkField, & _
            ForReading, False)
 Text1.Text = ""
 While Not FL.AtEndOfStream
  Text1.Text = Text1.Text & FL.ReadLine
 Wend
 FL.Close
End If

Set FL = Nothing
Set FSO = Nothing

Regards
Shaik Akthar

i tried that...am i not putting it in right?
i have...

rst.Open "SELECT Description From Equipment, con, adopenKeySet, adLockReadOnly

how am i supposed to do it?
i've also tried rst!description.

thank you very very much for your help shaik. you are a lifesaver

Daniel

here in this code it reads only the first record, opens the text file specified in the hyperlink column and displays its contents in the textbox.
Also note what the name of the textbox is in your form. here i have mentioned it as Text1. See that if u too have the same name of the textbox u created or anything else u might have changed the Name property of the textbox in which u r displaying the file contents.

u have not closed the quotation marks dear

rst.Open "SELECT Description From Equipment", con, adopenKeySet, adLockReadOnly

Regards
Shaik Akthar

i still can't seem to get it to work...i have tried soo many different ways!

u have not closed the quotation marks dear

rst.Open "SELECT Description From Equipment", con, adopenKeySet, adLockReadOnly

Regards
Shaik Akthar

i have exactly that, but the same error message appears!

PLZ POST THE ENTIRE CODE. I'LL JUST CORRECT IT OUT IF ANY MISTAKES.
ALSO UPLOAD THE DATABASE IF U CAN IN ZIP FORMAT.

Regards
Shaik Akthar

HEY con is the database object i referenced.
i think u have to use 'db'

unfortunately, i cant upload the database because the computer i am programming on does not have internet and i am using a seperate computer for this.

i tried db instead of con....still the same error message!

i'm sorry about the fuss, but i really can't thank you enough for all the help you have given me.

thank you
Daniel

also...the code i am using is exactly like the one you posted!...but its still juust that line that is giving me trouble!

use the following statement in declaring variables
Make sure to add Microsoft ActiveX Data Objects 2.1 Library in references

Dim db as New ADODB.Connection
Dim rst as New ADODB.RecordSet
Dim FSO As New FileSystemObject
Dim FL as TextStream

db.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & App.Path & "\database.mdb"

rst.open "SELECT DESCRIPTION FROM EQUIPMENT ", db, adopenKeySet, adLockReadOnly

If rst.BOF = False Then
  'open the file in the field which contains
  'the hyperlink to the textfile
  'here replace the hLinkField with the hyperlink field actually
  'in ur table

 Set FL=FSO.OpenTextFile(rst!Description, ForReading, False)
 Text1.Text = ""
 While Not FL.AtEndOfStream
  Text1.Text = Text1.Text & FL.ReadLine
 Wend
 FL.Close
End If

Set FL = Nothing
Set FSO = Nothing

Regards
Shaik Akthar

plz post the fieldnames and the sample data in those fields in the EQUIPMENT table

Regards
Shaik Akthar

IDNumber Name Description
101 Treadmill F:\treadmill.txt
102 Exercise Bike F:\exercisebike.txt

if you get the idea....description is a hyperlink data type

The hyperlink datatype adds a character '#' in the beginning and ending of the field value.

hence use the hLinkFile variable which holds the value of the Description field by eliminating the unnecessary # character using the Mid function

check if the file exists in the given path in the hLinkFile variable, and if yes then go for opening it and display its data.

put all the variables in the same procedure itself.

Imp: Add the following references.

1. Microsoft ActiveX Data Object 2.1 Library
2. Microsoft Scripting Runtime Library

Dim db As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim FSO As New FileSystemObject
    Dim FL As TextStream
    Dim hLinkFile As String

    Set db = New ADODB.Connection
    Set rst = New ADODB.Recordset
    db.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & App.Path & "\database.mdb"

rst.Open "SELECT DESCRIPTION FROM EQUIPMENT ", db, adOpenKeyset, adLockReadOnly

    If rst.BOF = False Then
        hLinkFile = Mid(rst!Description, 2, Len(rst!Description) - 2)
        If Dir(hLinkFile) <> "" Then
            Set FL = FSO.OpenTextFile(hLinkFile, ForReading, False)
            Text1.Text = ""
            While Not FL.AtEndOfStream
                Text1.Text = Text1.Text & FL.ReadLine
            Wend
            FL.Close
        End If
    End If

    If rst.State Then rst.Close
    Set rst = Nothing

    If db.State Then db.Close
    Set db = Nothing

    Set FL = Nothing
    Set FSO = Nothing

Regards
Shaik Akthar

I AM UPLOADING A SAMPLE PROJECT HERE FOR UR REFERENCE.


Regards
Shaik Akthar

Thank you soooooo much shaik!!!
thank you

Is ur problem solved. If solved then mark the thread as solved.

Anything else u may need feel free to ask anytime.


Regards
Shaik Akthar

AAH!! IT WORKS IT WORKS!!!

THAAANK YOOOU!...thank you soooo muuch!!
i can't believe how much you helped me and that you stood by me that whole time...even though it was so hard for me to understand!
you have no idea how much this means to me...THANK YOU THANK YOU THANK YOU!!
..you are beeeautiful!

From
a very happy Daniel

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.