Link to home
Start Free TrialLog in
Avatar of WS
WSFlag for United Arab Emirates

asked on

MS Access - Form - Upload document to Sharepoint form Access Form

Hi,

I have a Access database and a Sharepoint folder (with subfolders also) to store documents. I have a table that store all the metadata for document in Access.  I want to create a form that upload document to Sharepoint specific folder.  How could that be achieve through form? Is there any build in ways to do that? or do i have to write a VBA Code to get document form some location and then upload to a specific related folder in sharepoint?How that could be achieve?

Any help would be appreciated.

Thank you.
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

You will need VBA.

First, use Application.FileDialog  to select the file.
Next, use VBA.FileCopy  to copy the file to your Sharepoint folder.
Finally, save the full path in your table.

/gustav
SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WS

ASKER

Thank you Gustav and PatHartman for help, i set up everything and i wrote the code which Pat mention but it's giving an error, can you figure out why this error appear? User generated image
Go to Tools, References and add a reference to Microsoft Office 16.0 Object Library

/gustav
Avatar of WS

ASKER

User generated image How to make this error right? i want the user to select from Desktop or Document folder some file, how to do that?
Skip that - store the filename in a string variable:

    FileName = .SelectedItems.Item(1)

Then use FileCopy to copy the file.

/gustav
Avatar of WS

ASKER

I think i didn't explain well, there is a button a form as upload , there are two textbox as targetLocation and DestinationLocation. I want that when the user click on TargetLocation it should show something like this User generated image, user will select some document either pdf or word or excel or image, will click open and that location or path will be shown in target textbox. Then it will click on upload button and something should like this show User generated image where the user will select the destination location and will upload.

in my question where i mention
Code to get document form some location and then upload to a specific related folder
i mean all this.

The purpose of this form is to upload document from desktop/document somewhere to Sharepoint document library that is mapped in my local PC.

Any code to achieve this?

Thank you.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
' This requires a reference to the Microsoft Office xx.0 Object Library.  "xx = your office version
This was in the code I posted.

Me.txtFilePath is the name of a control on the form.  You could use a variable if you want to.  In my case, I was using a bound form and I wanted to save the path so I put the selected path into a control so it could be saved.

You need two controls.  One to pick the source DOCUMENT so you need to use --
Use msoFileDialogFilePicker if you want a file list rather than a folder list
for that text box.  Then use the sample code to pick the folder for the target.

The last step is to use
FileCopy Me.txtSourceFile, Me.txtSourceFolder

To copy the file.
Avatar of WS

ASKER

Thank you Gustav and PatHartman, and sorry for taking long to reply as i was setting up all the other requirements also.  Gustav , the code you wrote works well there is just one thing in that if you could help me in that as there are two fields in my table as Root Link and Target Link, Target link will get the path from txtTarget but i want that half of the link be saved in Root Link and half in Target Link. For example my link for Sharepoint is D:/Data/USA/2015, I want that the root link which is D:/Data( which will be same for all) should be save in Root Link and USA/2015 save in Target Link.

Also if you guys could guide me that the link which is there in Target Link field in table doesn't open like when click on that it should open that document but it's working , any idea why?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WS

ASKER

Gustav, some error pops up when i try to upload document into sharepoint folder (sharepoint server folder that is map to my local PC), to copy document from one file to another it work but to Share point folder it's not working it's giving error as shown in image.

When i copy document from one folder to another locally it's working , but to Sharepoint server/Sharepoint folder map to PC ,it is not working.

Any help?
error1.png
Can't tell. Here I can copy to one of our Sharepoint folders just like that - as to any local or network folder, like:

C:\Users\Gustav\OneDrive - Cactus Data ApS\Attached Files\Test.txt

Open in new window

/gustav
Avatar of WS

ASKER

don't we need any line of code to upload document to Server?
No. It is here:

FileCopy Me!txtSource.Value, Me!txtTarget.Value

Open in new window

/gustav
Avatar of WS

ASKER

FileCopy Me!txtSource.Value, Me!txtTarget.Value
The error which i mention is also in the same line which is copying the document to Sharepoint Server.

Also For one drive it's working. In my One Drive also it is uploading but in Sharepoint Server it is not uploading.

I tried using the field attachment also it is also not uploading in the Sharepoint mapped Folder.
I tried that - to the synchronised folder - and it worked with zero issues:

C:\Users\Gustav\Cactus Data ApS\Test - General\Testing.xlsm

Open in new window

Maybe you haven't been granted rights to save to such a location?

/gustav
Avatar of WS

ASKER

i'm the Site Owner for this document library in Sharepoint Server so i have the rights.

I'm still not able to get why this is giving the error i mention in this code for me.

Can i break this code to see error? If yes, how?
There is only this single line of code.
What does your target path look like?

/gustav
Avatar of WS

ASKER

this is how my target path look like: https://res.abc.org/St/Doc/D/ABW/abc
Yes, that won't work. You must have a mapped drive or a UNC path for FileCopy to work.

Synchronise the folder (or a parent folder) with your desktop, and then use the desktop folder path as target.

/gustav
Avatar of WS

ASKER

Gustav, can you explain a bit more because i am new to this.

What i have done is i open with Explorer from Sharepoint and then i add it as favorite and then it is there as folder under favorite field.

What's the difference between mapping and adding it like this, as i see they both work the same way.
error1.png
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WS

ASKER

Gustav this is the Sharepoint in Cloud, but i have Sharepoint Server like which is wihtin the organization in that you can't Sync.
Oh, then you must discuss your options with your admin.

/gustav
Avatar of WS

ASKER

i discuss with them and what they recommended is that there will be a code that will upload document to Server. The one code above it will work for folder , for Server few more lines have to be added , do you have any idea how to add server path?
FileCopy will accept a UNC path, something like:

\\servername\folder\St\Doc\D\ABW\abc

if that is what they mean. If not, another file copy method must be used.

/gustav
Avatar of WS

ASKER

do you have any idea how to use other method?

The code you provided is what i want and it work also it's just this one error that i am not able to resolve.
Untitled.png
I located this blog post which seems to list your alternatives:

Uploading Content Into SharePoint

Still, if you can obtain a UNC path to the folder, that's the simple method.

/gustav
Avatar of WS

ASKER

From where could i obtain UNC path?
From your Sharepoint administrator.

/gustav