Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set hyperlink property in a VB6 generated Database 1

Status
Not open for further replies.

Homersim2600

Technical User
Dec 15, 2004
253
US
Hello,
I am working on a program that will enable the user to visit a webpage via a hyperlink within a database. I am using ADOCTL and Datagrid to display the database within my VB form. I have looked at all of the formatting properties and I am unable to figure out how to insert the hyperlink property for a field. I guess you should also know that I created the database using a VB program I found on this site, and I don't have access to MSAccess in order to change the property of this field. Do you know how to format a field to become a hyperlink in a database displayed in VB6 programatically?

Oh, If I need to recreate the database, and/or, use something other than ADODC/datagrid, then I am all up for it; anything to get this to work. I really appreciate your help. Thank you.

LF
 
Hello again Homersim2600!

I have a solution, but I would first like to see the code you use to create the table. The soultion I have may require rebuilding the table from scratch, and I want to see if you are already using the method I have to build the table.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Option Explicit
Private wrkDefault As Workspace
Private dbsNew As Database
Private tdfNew As New TableDef
Private cnn As New ADODB.Connection
Private cmd As New ADODB.Command
Private strcnn As String
Private RS As New ADODB.Recordset
Private sDataBaseName As String


Function CreateDB()
Dim isThere As Boolean

On Error GoTo err
isThere = FindFile("C:\spider\BotData.mdb")
If isThere = True Then
MsgBox "This Database already exsist. If you would like to delete the file, then close this program and delete the file, otherwise proceed with using the program...", vbCritical, "OOPS!!!"
Exit Function
Else
End If

sDataBaseName = "C:\spider\BotData.mdb"
Set wrkDefault = DBEngine.Workspaces(0)
Set dbsNew = wrkDefault.CreateDatabase(sDataBaseName, _
dbLangGeneral, dbEncrypt) 'Create New DataBase
Set dbsNew = wrkDefault.OpenDatabase(sDataBaseName, True, False) 'open the created Database
Set tdfNew = dbsNew.CreateTableDef("BotData") 'Create Table

With tdfNew
.Fields.Append .CreateField("Date", dbDate) 'Create a new field with text as data type
.Fields.Append .CreateField("SiteName", dbMemo, 255)
.Fields.Append .CreateField("SiteLink", dbMemo, 255)
.Fields.Append .CreateField("BaseURL", dbMemo, 255)
.Fields.Append .CreateField("Keywords", dbMemo, 255)
.Fields.Append .CreateField("DeniedBot", dbBoolean, 20)
.Fields.Append .CreateField("WebPage", dbMemo, 255)

End With

dbsNew.TableDefs.Append tdfNew 'add the table to the DB
dbsNew.Close 'close database
err:
If err.Number = 3204 Then 'DB exists
' Kill sDataBaseName
Resume
End If
End Function

'Here's the code for the second Database

Function CreateDB2()
Dim isThere As Boolean

On Error GoTo err
isThere = FindFile("C:\spider\BotData2.mdb")
If isThere = True Then
MsgBox "This Database already exsist. If you would like to delete the file, then close this program and delete the file, otherwise proceed with using the program...", vbCritical, "OOPS!!!"
Exit Function
Else
End If

sDataBaseName = "C:\spider\BotData2.mdb"
Set wrkDefault = DBEngine.Workspaces(0)
Set dbsNew = wrkDefault.CreateDatabase(sDataBaseName, _
dbLangGeneral, dbEncrypt) 'Create New DataBase
Set dbsNew = wrkDefault.OpenDatabase(sDataBaseName, True, False) 'open the created Database
Set tdfNew = dbsNew.CreateTableDef("BotData2") 'Create Table

With tdfNew
.Fields.Append .CreateField("Date", dbDate, 20) 'Create a new field with text as data type
.Fields.Append .CreateField("SiteLink", dbMemo, 255)




End With

dbsNew.TableDefs.Append tdfNew 'add the table to the DB
dbsNew.Close 'close database
err:
If err.Number = 3204 Then 'DB exists
' Kill sDataBaseName
Resume
End If
End Function

I found this code via a FAQ on this web site somewhere and customized it to accomodate my needs.

Thank you for your time...

LF



"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Okay, here's how to do it:

After you append the field to the table (but before you append the table to the database) you have to set the attributes of the field to make it a hyperlink:

With tdfNew
.Fields.Append .CreateField("Date", dbDate) 'Create a new field with text as data type
.Fields.Append .CreateField("SiteName", dbMemo, 255)
.Fields.Append .CreateField("SiteLink", dbMemo, 255)
.Fields("SiteLink").Attributes = dbHyperlinkField
.Fields.Append .CreateField("BaseURL", dbMemo, 255)
.Fields.Append .CreateField("Keywords", dbMemo, 255)
.Fields.Append .CreateField("DeniedBot", dbBoolean, 20)
.Fields.Append .CreateField("WebPage", dbMemo, 255)

End With

I did it on the SiteLink field because I don't know exactly which field you want as the hyperlink. Just change the location of the line of code and put in the appropriate field name and it should work fine.

However, I would suggest that you move away from DAO to do any type of database programming and instead use ADO exclusively. ADO is newer technology (although it is now being phased out in favor of ADO .NET) - DAO is soon to be no longer supported by Microsoft (or maybe already not supported, I'm not sure). And, since you are new to DB programming, you shouldn't have to relearn too much to make the switch. As to this specific problem, here is a link that details how to create an Access table using ADO:

Creating and Modifying Access Tables

Anyway, I hope this helps.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
ahhhhh! Thank you very much for this information... This code that I am using was on a FAQ here at Tek-Tips, it worked, and so I used it :) . Thanks for letting me know that it is being phased out, and double thanks for supplying me with all of this helpful information.


LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top