Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2005
    Posts
    333

    Unanswered: Map network drive

    From a command window I can type
    net use s: /delete
    net use s: \\myComp\myDir
    and map the given path to the s:\ drive. How can i do this from VBA?

  2. #2
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    try the Shell command

  3. #3
    Join Date
    Feb 2005
    Posts
    333
    I'm looking at that now. Having a little trouble converting to VBA.
    For the given code, VBA is expecting an "=" sign.
    Code:
    Set wshnetwork = CreateObject("WScript.Network")    
    wshnetwork.mapnetworkdrive("z:","\\myComp\myDir")
    Last edited by campster; 04-11-06 at 16:30.

  4. #4
    Join Date
    Feb 2005
    Posts
    333

    Got it but I'm a little confused.

    This works
    Code:
    Set WshNetwork = CreateObject("WScript.Network")    
    WshNetwork.MapNetworkDrive "z:", "\\myComp\myDir"
    The question I have is: why do some functions require parenthesis and some crash if parenthesis are used?

  5. #5
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    The difference is a Function versus a Sub. When you call a function you use the parenthesis and it is assumed that a value will be returned. Where as, a Sub does not return anything and no parenthesis are required. Example

    strSomething = SomeFunction(Parameter1, Parameter2)

    SomeSub Parameter1, Parameter2

    It is also acceptable to call a sub with parenthesis but you have to use the Call keyword (I use this in the Immediate window of the editor to test a sub)

    Call SomeSub(Parameter1,Parameter2)

    The Call informs Access that no value will be returned.

  6. #6
    Join Date
    Feb 2005
    Posts
    333
    Thanks for the explanation. Now I'll see if my pea brain will be able to remember it for more than a day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •