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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlinks in List Box

Status
Not open for further replies.

icupat

Technical User
Aug 6, 2002
25
CA
Ok. Here's what I want to do:

I've got a browse button that pulls up a MULTI-SELECTABLE explorer window. If I select 5 files, I want the list box to be populated with these five name (JUST the filename), and then I want them all hyperlinked to the proper location (pathname+filename). So that if I double click on any name in the list box it opens up to the file.

This may not be possible, so I dunno... I'm mainly looking for help with the hyperlinking of mutliple filenames part... thanks.
 
nevermind. found a solution that involved a commondialog box, a list box and a some visual basic...

for those interested here's the code, there's a few subs... each should be self-explanitory... one important thing is that you need to create a dummy label called "myhyperlink" and you can make it "not visible" in the properties. The label is used to direct the hyperlinking.:

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
lStructSize As Long
hWndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrfile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Sub browsefile_Click()

Const OFN_ALLOWMULTISELECT = &H200&
Const OFN_EXPLORER = &H80000
Dim filenames$()

Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hWndOwner = Me.hwnd
'Set the application's instance
'OFName.hInstance = App.hInstance
'Select a filter
OFName.lpstrFilter = "Jpegs (*.jpg)" + chr$(0) + "*.jpg" + chr$(0) + "All Files (*.*)" + chr$(0) + "*.*" + chr$(0)
'create a buffer for the file
OFName.lpstrfile = space$(1054)
'set the maximum length of a returned file
OFName.nMaxFile = 1055
'Create a buffer for the file title
OFName.lpstrFileTitle = space$(1054)
'Set the maximum length of a returned file title
OFName.nMaxFileTitle = 1055
'Set the initial directory
OFName.lpstrInitialDir = "\\Dataserver\"
'Set the title
OFName.lpstrTitle = "Open File"
'No flags
OFName.flags = OFN_ALLOWMULTISELECT Or OFN_EXPLORER

'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then

z = 1
For i = 1 To Len(trim$(OFName.lpstrfile))
i = InStr(z, trim$(OFName.lpstrfile), chr(0))
If i = 0 Then Exit For
ReDim Preserve filenames(Y)
filenames(Y) = Mid(trim$(OFName.lpstrfile), z, i - z)
z = i + 1
Y = Y + 1
Next

'If Y = 1 Then
' mylistbox.RowSource = filenames(0) & ";"
'Else
mylistbox.RowSource = ""
For i = 1 To Y - 2
'If i = 0 Then
' mylistbox.RowSource = filenames(0) & "\" & ";"
'Else
mylistbox.RowSource = mylistbox.RowSource & filenames(i) & ";"
'End If
Next i
'End If
Me![directory] = filenames(0) & "\"
Else
MsgBox "You Have Canceled Your Browsing"
End If

End Sub

Private Sub Form_Current()

On Error Resume Next

Me![imageframe2].Picture = Me![directory] & [mylistbox]
End Sub

Private Sub mylistbox_Click()
On Error Resume Next

Me![imageframe2].Picture = Me![directory] & [mylistbox]
End Sub

Private Sub mylistbox_DblClick(Cancel As Integer)

On Error Resume Next

myhyperlink.HyperlinkAddress = Me![directory] & mylistbox
myhyperlink.Hyperlink.Follow

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top