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

compile error 1

Status
Not open for further replies.

Krystian81

Programmer
Sep 10, 2012
11
PL
when I try to run this function ( I`ve also tried to change it to Sub ) I get error
"in the sub procedure calls can not use parent objects"

Function map_drive(drive_letter, drive_to_map)

Dim objNetwork, strDrive

Set objNetwork = CreateObject("Wscript.Network")

strDrive = drive_to_map
objNetwork.MapNetworkDrive drive_letter, strDrive

End Function
 
Well, my guess is that it doesn't like the object creation inside a function.

Also, why are you re-assigning the variable 'drive_to_map' to a new variable (strDrive)?

Will this work instead?:
Code:
Dim objNetwork,result
Set objNetwork = CreateObject("Wscript.Network")

result = map_drive("H:","\\FS01\Home")

Function map_drive(drive_letter, drive_to_map)

 objNetwork.MapNetworkDrive drive_letter, drive_to_map

End Function

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
yeah, I was trying to test something and assign this in stupid way

your code works fine.

my also work but I had to use Call <functionName>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top