Finding and opening a hyperlink

zebrafoot

Member
Local time
Today, 18:55
Joined
May 15, 2020
Messages
77
Hello everyone,

Our company database has a facility to add a folder containing pictures or files of any inventory items we keep. There's a button in the appropriate form that has an "on click" command to check to see if there's any folder in the appropriate place for the numbered inventory item. If yes, then that link is opened, if no, the user is offered the option to make a folder.

The code for checking for the presence of the folder is as follows:

Dim strInventoryID As String 'needs to be a string for the hyperlink?
strInventoryID = Me.InventoryID
Dim strDir As String
strDir = "a:\Inventory Images\" & strInventoryID

Dim MyDir As String
MyDir = strDir


If Len(Dir$(MyDir, vbDirectory)) > 0 Then
FollowHyperlink "A:\Inventory Images\" & strInventoryID 'should open folder corresponding to this InventoryID
Else

If MsgBox("There isn't a folder yet; would you like to create one?", vbQuestion + vbYesNo, "Create Folder?") = vbNo Then
Exit Sub
End If
MkDir strDir
FollowHyperlink strDir


End If


This all works fine. However, my boss would like to access the folders from outside the database, so it's helpful to him to annotate the folder names with some info that makes sense - eg "145 - Fred Bloggs broken whatnot". My understanding is that I can't open a hyperlink using a wildcard, so is there a straightforward way to return the name of a folder with the starting path name to match the string strDir as defined above, so that I can then open it?

Many thanks in advance.

Pete
 
as suggeted you can modify your code to this:
Code:
Dim strInventoryID As String 'needs to be a string for the hyperlink?
strInventoryID = Me.InventoryID
Dim strDir As String
strDir = "a:\Inventory Images\" & strInventoryID

Dim MyDir As String
MyDir = Dir$(strDir & "*", vbDirectory)


If Len(MyDir) > 0 Then
    FollowHyperlink "A:\Inventory Images\" & MyDir 'should open folder corresponding to this InventoryID
Else

    If MsgBox("There isn't a folder yet; would you like to create one?", vbQuestion + vbYesNo, "Create Folder?") = vbNo Then
        Exit Sub
    End If
    MkDir strDir
    FollowHyperlink strDir


End If
 

Users who are viewing this thread

Back
Top Bottom