VBA to Create and Open Variable Folders with a Link Created in an Access Query (1 Viewer)

theimel

New member
Local time
Today, 02:01
Joined
Aug 5, 2014
Messages
2
I am trying to set up something to be able to take me to a folder that holds various forms for personnel. I have a query that generates the link for each person. I have tried to set it up as a hyperlink in ACCESS 2013 and it displays as one but doesn't act like one.

I want to be able to click the link and have it open up a personnel folder for that individual. I can't find a MACRO that I can create to do it and I have no idea how to program in VBA, which I know is how I will need to solve the problem, so if you give me something you need to be pretty specific in how to type it out. Example of my query is that it creates a link K:\Main Breakdown\Section Breakdown\Personnel Folders\Name and the name is the variable part.

My next problem will be to have it create that folder when we have new personnel arriving.

I would also note that I have not worked with ACCESS in many years and much of what I was able to do with 2002 and 2003 doesn't work with the newer versions of ACCESS.
 

DavidAtWork

Registered User.
Local time
Today, 10:01
Joined
Oct 25, 2011
Messages
699
You could try using the Dir & MkDir to create the folder and the FileDialog object to open a dialogue box which will go straight to that folder.
Creating a folder (if it doesn't already exist) is quite straightforward,
Code:
If Dir("K:\Main Breakdown\Section Breakdown\Personnel Folders\Name ", vbDirectory) = "" Then
    MkDir "K:\Main Breakdown\Section Breakdown\Personnel Folders\Name "
End If

to use the FileDialog, you could pass the location of the folder to a function

Code:
Function openMyFolder(thePath as String)
Dim fp As FileDialog
Set fp = Application.FileDialog(msoFileDialogFolderPicker)
With fp
    .InitialFileName = thePath
    .Show
End With
End Function

David
 

theimel

New member
Local time
Today, 02:01
Joined
Aug 5, 2014
Messages
2
Like I stated originally I don't know VBA and not sure what to do with it once I create the module. I assume since all the other Modules have

Option Compare Database
Option Explicit

I need the same for these two functions. I am not sure how it gets the loction from my list of locations that I plan to one displayed on the form for the individual. I also am not sure how to execute the Modules.

I am sorry if I am frustating but I have not done programming in about 25 years and it is a lot differant than what I did back then.
 

DavidAtWork

Registered User.
Local time
Today, 10:01
Joined
Oct 25, 2011
Messages
699
Presumably the links you created from your query for each personnel are stored in a table and you say it is displayed somewhere, is this on a form using a text box, if so you can add a small button and use the OnClick event to execute the code above.
It should be something like

Code:
If Dir(Me.pathLink, vbDirectory) = "" Then
    MkDir Me.pathLink
End If
where Me.pathLink is the name of your text box

The function openMyFolder can be pasted into any module and can be called from anywhere, when it is called you just need to pass the path to it using:

Code:
openMyFolder CStr(Me.pathLink)

Again you could use a button labelled "Go to folder" and paste the code above into the OnClick event

David
 

Users who are viewing this thread

Top Bottom