Using wildcards

Geezer

Registered User.
Local time
Tomorrow, 08:37
Joined
Jul 14, 2008
Messages
62
Have created a bit of code so when a user clicks on a button it open Explorer in the correct folder location, here's my code:

Private Sub Cmd_OpenExp_MEDLoc_Click()

Dim ProjPath
ProjPath = "G:\MED Data\" & Me.MED_FolderLink.Value

Shell "C:\WINDOWS\explorer.exe """ & ProjPath & "", vbNormalFocus
End Sub

MED_FolderLink is a field into which the user puts the end of the folder location. However, it's kinda redundant as there is another field in the form which represents the first couple of characters of the folder. So ideally I'd like the code to look something like this:

Private Sub Cmd_OpenExp_MEDLoc_Click()

Dim ProjPath
ProjPath = "G:\MED Data\" & Me.PR_NO.Value

Shell "C:\WINDOWS\explorer.exe """ & ProjPath & "*" & "", vbNormalFocus
End Sub

Of course it doesn't like the "*" and returns a directory not found message.

Is there any way of making the code above work? The PR_NO value might look something like

PR 0673

while the folder reference might look like

G:\MED Data\PR 0673 Parara-1

They're essentially the same though, but without manually inputting the folder path there seems to be no way around it.

Any help would be appreciated
 
Well you can use i.e. Dir or FileSearch to find the exact directory name using wildcards, then pass the right path to the Explorer.
 
Thanks Mailman,

Would someone mind giving a simple example? I'm not having any luck, Explorer is opening but only as far as the root directory.

An example of the basic setup:

PR_NO field contains PR numbers:

PR 0678
PR 1289
PR 3465, etc, etc

The "root" folder address is

G:\MED Data\

There are then folders within that root address that look something like:

G:\MED Data\PR 0678 Griffin
G:\MED Data\PR 1289 Parara
G:\MED Data\PR 3465 Moho, etc, etc

I'm wanting to open Explorer in the above folders when on each given PR_NO record so essentially I'm needing to call the G:\MED Data\ folder plus the PR_NO field value plus a wildcard (*, or the likes).

Any takers?

Would be much appreciated.
 
Presuming there is only one directory you can use the DIR command and a wildcard to find the exact directory name, i.e.
?Dir("C:\Win*", vbDirectory)
WINDOWS

So now I know the C:\Windows folder excists and and I open said folder in Explorer.
 
Thanks again Mailman,

Taking your example:

?Dir("C:\Win*", vbDirectory)

Could one use a field value on a given form in place of the Win?

e.g.

?Dir("C:\Me.Windows.value*", vbDirectory)

Perhaps a silly question but why is there a ? in front of Dir?

Apologies for lack of knowledge, I'm VERY new to this.

Cheers,

Gareth
 
Well you allready know how to substitute text in...
Dir("C:\" & Me.Windows.value & "*", vbDirectory)

The ? is there because I executed the line in the Debug Window to test it.
 
Hmm, thought I tried this earlier but it didn't work :confused:

I'll have another go at it in the morning.

Well you allready know how to substitute text in...
Dir("C:\" & Me.Windows.value & "*", vbDirectory)

The ? is there because I executed the line in the Debug Window to test it.
 
Excellent

Brilliant, got it to work, thanks heaps.

Well you allready know how to substitute text in...
Dir("C:\" & Me.Windows.value & "*", vbDirectory)

The ? is there because I executed the line in the Debug Window to test it.
 
Hello there,

What was the final code you used??? I have the same problem. I can open folder but soon as i use the wild card function as described in messages in errors and just opens default explorer window.

The code I am using

Dim ProjPath As String
Dim stProject As String

stProject = Me![Text115]
ProjPath = Dir("K:\ACTIVE\" & stProject & "*", vbDirectory)

Shell "C:\WINDOWS\explorer.exe """ & ProjPath & "", vbNormalFocus


Any help would be appreciated..
Thanks
 
Your missing a "" ...
Shell "C:\WINDOWS\explorer.exe """ & ProjPath & "", vbNormalFocus

should be
Shell "C:\WINDOWS\explorer.exe """ & ProjPath & """", vbNormalFocus

Still I dont think you can use a wildcard to open a folder in the explorer though...
 
thank you for that, your rite it doesnt work..

Do you know of anyway to open a folder with the same name as a form field but with the folder having extra characters on the end??

Thanks
 
You could use the dir command
?Dir("C:\Win*", vbDirectory)
WINDOWS

To find the full name, then use the full name to open the folder... That is assuming there is only one folder...
Otherwize you have to loop thru and open multiple folders in multiple explorer windows.
 
Sorry Im new to Access, I dont know how to use the Dir command, what do I do?

Thanks
 

Users who are viewing this thread

Back
Top Bottom