Map network drive using EnumNetworkDrives gives object required error in access 2013

I need to map network drives to copy a file !  I tried to use the microsoft suggested function getnextletter but am getting errors.
Seems the oDrives is not an object As I get object required at that line!

    Public Function GetNextLetter(DriveLetter)
          'Start x at the ascii value of the drive letter to start the search
       'unless something is passed in. This sample uses capital letters and
       'starts at F.
       If IsEmpty(DriveLetter) Then
        x = 70
       Else
        x = Asc(DriveLetter)
       End If
   
       Set oDrives = wshNet.EnumNetworkDrives

       'Step by two since the first item in the collection is the drive letter
       'and the second item is the network mapping
       For i = 0 To oDrives.Count - 1 Step 2
        If Chr(x) & ":" = oDrives.Item(i) Then
            x = x + 1
        End If
       Next
   
       GetNextLetter = Chr(x) & ":"
    End Function

The VBA that references this function is!

Private Sub Command0_Click()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshNet = CreateObject("WScript.Network")

strSource = GetNextLetter("F")
wshNet.MapNetworkDrive strSource, "\\TQFPRK06\project management\"
strDestination = GetNextLetter("F")     '<-- You can change the letter.  It represents the starting letter to work from.
wshNet.MapNetworkDrive strDestination, "\\TQFPRK06\Tech_drive\"
strSource = strSource & "test.xlsx"

objFSO.CopyFile strSource, strDestination & "\"
wshNet.RemoveNetworkDrive strDestination, True
wshNet.RemoveNetworkDrive strSource, True

Set objFSO = Nothing
Set wshNetwork = Nothing
End sub


Thanks

Pete
Peter GrovesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

als315Commented:
You can't use object without declaration. As a test you can declare wshnet as global object immediately after Option Compare Database in the beginning of module:
Global wshnet As Object

I don't like to have global variables, because it may be changed anywhere and it will be difficult to debug it. I prefer also to declare all used variables and add Option Explicit to any module. In this case you will get an error on any non declared variable.

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
Peter GrovesAuthor Commented:
Thats what my problem was , thanks.  

Pete
als315Commented:
Author confirmed answer, but forgot to close question
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 Access

From novice to tech pro — start learning today.