VBA Target Path (1 Viewer)

Neilster

Registered User.
Local time
Today, 13:44
Joined
Jan 19, 2014
Messages
218
Hi Guys

I'm trying to set the desktop icon using VBA which is fine, however the shotcut isn't picking up the target path.

Any ideas?

With CreateObject("WScript.Shell")
With .CreateShortCut(.SpecialFolders("Desktop") & "\Demo Database.lnk")
.TargetPath = Environ("userprofile") & "\Documents\Demo Database\DemoDatabase.accdb"
.WindowStyle = 1
.Hotkey = ""
.IconLocation = Environ("userprofile") & "\Documents\Demo Database\cloud.ico, 0"
.Description = "Test Icon Substitution"
.WorkingDirectory = Environ("userprofile") & "\Documents\Demo Database\DemoDatabase.accdb"
.Save
End With
End With
 

Minty

AWF VIP
Local time
Today, 21:44
Joined
Jul 26, 2013
Messages
10,371
What do you get if you debug.print Environ("userprofile") ?
 

Neilster

Registered User.
Local time
Today, 13:44
Joined
Jan 19, 2014
Messages
218
Hi Minty

Thanks for getting back to me, I've sorted it and the code works fine, just me being silly. However I am trying to get it from a Network drive and can't get it to work???

:banghead::banghead::banghead:
 

GinaWhipp

AWF VIP
Local time
Today, 16:44
Joined
Jun 21, 2011
Messages
5,899
Hmm, get it from a Network Path? You mean copy the Shortcut from the Network or have the Shortcut link from the Network?

Note, when using the Network use the UNC Path not a drive letter.
 

Minty

AWF VIP
Local time
Today, 21:44
Joined
Jul 26, 2013
Messages
10,371
A network path won't have a Environ("userprofile") - that is a local machine environment string.

As Gina said a network path would be something like \\Server\SharedFolderName\yourfile.pdf
 

Neilster

Registered User.
Local time
Today, 13:44
Joined
Jan 19, 2014
Messages
218
But is there a geniric path for any Network target like the environ?
 

Minty

AWF VIP
Local time
Today, 21:44
Joined
Jul 26, 2013
Messages
10,371
No, by definition a network share would be completely specific to the network you are connected to.

We store dedicated storage paths in a system table, and look them up at database startup. This means if we ever move a centralised store we only need to change the value in the table once - not recode the whole thing.

So the value today for the field InvStoragePath might be \\Datastore\Invoices but if we had to, we could change it to \\NewData\Invoices by simply updating the field value.
 

Users who are viewing this thread

Top Bottom