VB Word 97 - Connect/Disconnect Network drive

Hello,
I've written a routine to present the Connect Network drive dialog (for password entry)
, then open a file on that drive once the connection is made.

With Dialogs(wdDialogConnect) etc


I'd like to have Word check to see if the connection already exists...
i.e. "If drive "s" is aready mapped to \\nataol\sco, then go straight
to file open, else go to DialogConnect statement.  I just
can't get my head around how to phrase it.

Also, once the editing is complete (which is carried out in the macro)
I'd maybe like the drive to disconnect - not essential, would be nice though
Is there code for this?

Cheers
Struds
LVL 1
StrudsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NoggyCommented:
Struds - I have a list of DriveMapping functions at the following Q:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=msaccess&qid=10215848 

You may find them useful (including the Disconnect one). And, the Q'er hasn't accepted the answer yet, so you won't need to pay to view the link above - though you will need to pay for this one if you use them :-) .
0
ahammarCommented:
I know you can map and unpam drives with a batch file. I don't know how to do it personally, but if you do, you could write a batch file to connect or disconnect the drive, and run the batch file from Vba.
You can probably do it directly with vba also, but I don't know that one either, but someone else will.
Also, if you need, then I can get the syntax for writing a batch file to do that when I get to work tomorrow.

cheers!
ahammar
0
NoggyCommented:
ahammar - "Unpam"? :-) Someone's "unpammed" your brain from your hands :-p . Also, you can do it directly with VBA 'cos that's the code that I've referred Struds to. Have a look - you may like/use it :-)

PS Are you following me around tonight? "Help, I'm being stalked" :-)
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

StrudsAuthor Commented:
Noggy - you are a goose!!

You code looks terrific - I've printed it out and will have a go tomorrow (so give me a couple of days to play!), however I must point out that I'm not an api/vb expert, so I may come back with a dumb question or two.  I've never used functions to this extent!

Thanks both for your input so far.  Talk to you soon
Cheers
Struds
0
NoggyCommented:
Honk! Honk! :-)

No problem about the questions. Let me know if you need any help. Just think of it as a good learning experience :-).

Simply paste the code in a separate module (preferably) and address the functions as necessary. Looking at it though, I may put some comment code in to inform you of what each argument for each function can contain.
0
ahammarCommented:
Noggy,
Geeezzz, "Unpam" , I am defineately with it tonight...!
I knew if I followed you around long enough, You'de eventually lead me to something good.......:-)
I'm going there now to check out those functions. Maybe I can change them a little to make them "Pam" drives also, in case I ever need to do that....:-)

Struds: I might have been wrong. I don't think you can get a batch file to "unpam" a drive, so please don't try....:-)

Cheers!
ahammar
0
ahammarCommented:
Noggy,
I went there and saved the whole page on my hard drive. I must say that stalking you has paid off.....:-)
That's good stuff!
Wanna see a trick. Watch me make this center column really wide.
****************************************************************************************************
Thanks for everything!!
ahammar
0
ahammarCommented:
oops!
Didn't mean to make it that wide. Hope that doesn't bother anybody. Sorry if it does.
It's something to remember though if you want to make sure any code you post doesn't wrap to the next line. That was 100 asteriks, so I wouldn't use quite that many.

Sorry again.

Cheers!
ahammar

0
StrudsAuthor Commented:
Ahammar - now you're the goose.  I've just read down this page thinking "ooer, what's happened to my exchange page.  must be something wrong with my settings...bla bla"

Thanks a lot ;-)
tee hee

Struds
0
NoggyCommented:
Yeah, ahammar, I saw that tip on the Support page too. Hopefully, they'll sort it soon though so that we don't have to stoop to such underhand measures :-)
0
StrudsAuthor Commented:
Hi Noggy,

Thanks again for the routines you'd written.  I've created them - no worries, now - how do I call them from my macro?  I just don't quite understand the Module/Macro division, so am unsure how to proceed and include them in my code, which, once the document is open, goes through and edits/prints it.  The doc will then close, then the "DisconnectNetworkDrive" routine should run.

Is it a "call" or "run" type statement?  Do I need to declare them at the beginning, or something?

Please assume I know nothing!

Cheers
Struds
0
StrudsAuthor Commented:
Adjusted points to 200
0
NoggyCommented:
Hi Struds, I'll give you the code tonight - I'm at work now and don't have the time :-( .
0
NoggyCommented:
Struds - This is a bit of code that you can use. I have put it all in a VBA procedure called MySub(). Just paste your code into the relevant places where I have the MsgBox statements:

Public Sub MySub()
    If GetUNCPath("S") <> "\\nataol\sco" Then
        MsgBox "Put your Connect dialogue and code here unless you want to connect automatically."
    End If
   
    MsgBox "Put your main code here"
   
    DisconnectNetworkDrive "S", True
End Sub

If you want to call MySub from another procedure, you don't need the Call or Run statements (as long as the code is in the same VBA project - i.e. in your Word project). So, if you have your main code in a sub called Main(), you can execute MySub() using the following:

Public Sub Main()

     '<<Your code>>
     MySub'This executes the other procedure
     '<<More of your code>>
End Sub

To make it even nicer, you can turn the MySub() procedure into a function so that you can check that it has executed properly:

Public Function MySub() As Boolean
    On Error GoTo MySub_Error
    'Assume that the function will be successful
    MySub = True
   
    If GetUNCPath("S") <> "\\nataol\sco" Then
        MsgBox "Put your Connect dialogue and code here unless you want to connect automatically."
    End If
   
    MsgBox "Put your main code here"
   
    DisconnectNetworkDrive "S", True

MySub_Exit:
    Exit Function
   
MySub_Error:
    MySub = False
    Resume MySub_Exit
End Function

You can then call it like this:
Public Sub Main()

     '<<Your code>>
     If Not(MySub) Then'This executes the other procedure
         'and checks to see if the function was executed successfully - or not in this case
          MsgBox "An unexpected error occurred"
     End If

     '<<More of your code>>
End Sub

The Not(MySub) is the same as saying:
If MySub = False Then ....

I haven't tested the code above as I do not have a network at home. However, I shall give it a little test at work tomorrow. Let me know if you need any more help.
0
NoggyCommented:
I've tested it out. This code should work for you:

Public Function MySub() As Boolean
    Dim sErrMsg As String
   
    On Error GoTo MySub_Error
    'Assume that the function will be successful
    MySub = True
   
    If GetUNCPath("S") <> "\\nataol\sco" Then
        MsgBox "Put your Connect dialogue and code here unless you want to connect automatically."
    End If
   
    MsgBox "Put your main code here"
   
    DisconnectNetworkDrive "S:", True, sErrMsg

MySub_Exit:
    Exit Function
   
MySub_Error:
    MySub = False
    Resume MySub_Exit
End Function
0
StrudsAuthor Commented:
THanks heaps, Noggy.

I'll try it out tomorrow or Friday and let you know how I go

Cheers
Struds
0
NoggyCommented:
Okey-dokey
0
StrudsAuthor Commented:
Hi Noggy,  Just wanted to let you know I hadn't abandoned this!!!  Just haven't had a chance to test it out - will keep you posted.

Cheers
Struds
0
NoggyCommented:
OK
0
StrudsAuthor Commented:
Noggy,

FINALLY - I got around to it and I've had success!!

Thanks for the routines and assistance.  Please post an answer, and the points are all yours

And thanks for your patience!

Cheers and happy new year (but not millenium yet!)

Struds
0
NoggyCommented:
No problem, Struds. I'm glad that you've had success.

Have a happy new year yourself.

PS Hopefully, you're monitoring your mail today so that I can get the points before tomorrow. That way, I may break the 15000 point barrier. That would be nice for the New Millennium, wouldn't it?


PAQ Viewers: Please see my comments below for the full solution to the answer.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StrudsAuthor Commented:
Thanks again Noggy - sorry I didn't make the 1-1-00 date!!

PS do we call these the "naughties" now?? (as opposed to the nineties)?????

or maybe the "0-zone"

maybe I'll start a thread.....

cheers
struds
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.