Avatar of MarkSnark1
MarkSnark1

asked on 

Use Access 2010 macro and VBA code XCopy Folders and Files from network server to Tablet.

I need create an Access Macro that will copy folders and files from a server to a directory on tablet attached to the local workstation.  \\oiclx\public\tabletsync e:\.   I can either execute this from a macro, use vba from command button, run a batch file--which ever is best and least complicated but reliable.  Thank you.
Microsoft AccessVB Script

Avatar of undefined
Last Comment
MarkSnark1
Avatar of kmslogic
kmslogic
Flag of United States of America image

Something like this should work in a button click event to copy your files (in VBA):


    Dim strFile As String
   
    strFile = Dir("\\oiclx\public\tabletsync\*.*")
    While strFile <> ""
        FileCopy strFile, "E:\"
        strFile = Dir()
    Wend
Avatar of MarkSnark1
MarkSnark1

ASKER

I made the button as Kmslogic prescribed below but nothing happens when the button is pushed, no error message, no trouble shooter, nothing.  I appreciate your help.  While this looks like something that will work well for my purposeses it must need another tweak.

Private Sub Sync_Click()
  Dim strFile As String
   
    strFile = Dir("\\oiclx\public\tabletsync\*.*")
    While strFile <> ""
        FileCopy strFile, "E:\"
        strFile = Dir()
    Wend
 
End Sub


Avatar of kmslogic
kmslogic
Flag of United States of America image

Put a breakpoint (place your cursor on the strFile=Dir line and press the F9 function key) in the VB editor and then click the button.   Make sure we're getting into the function.  If we are then you can step through each line by pressing SHIFT-F8.  
Avatar of MarkSnark1
MarkSnark1

ASKER

Thank you for responding.  I put a bread point in where you said, saved the form, tried it again and still nothing happens.
Avatar of kmslogic
kmslogic
Flag of United States of America image

Ok if nothing happens then that function isn't set as your click event on the button.  Right click on the button and select properties so the properties box appears.  Click on the events tab.  Press the "..." button next to the event and select "Code Builder" and click Ok.  Put your code in the function it gives you.
Avatar of MarkSnark1
MarkSnark1

ASKER

Yes, That is what I showed you above after you gave the original code. Is there a way to check if "Filecopy" is a valid command on my system?  I am using Office/Access 2010.
ASKER CERTIFIED SOLUTION
Avatar of kmslogic
kmslogic
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of MarkSnark1
MarkSnark1

ASKER

I was told that the event was not set up correctly but I set it up three different times to put the code in the Click event on the button and the code just is not running.  I showed the resulting setup from the vba editor.  I don't know what else to do.
Avatar of kmslogic
kmslogic
Flag of United States of America image

I understand your frustration, but really you shouldn't accept the answer if it doesn't solve your problem. If the on click event is set up correctly then you aren't setting up the breakpoint correctly.  I really has to be one of those two things.  When you press F9 on the line:

strFile = Dir("\\oiclx\public\tabletsync\*.*")

it should be highlighted in a dark red color which signifies the breakpoint is in place.  Then when you press the button on your form it should stop at this line of code.
Avatar of kmslogic
kmslogic
Flag of United States of America image

A couple of changes to what I sent you (of course you would have gotten an error message--not just "nothing"):


    strFile = Dir("\\oiclx\public\tabletsync\*.*")
    While strFile <> ""
        FileCopy "\\oiclx\public\tabletsync\" & strFile, "E:\" & strFile
        strFile = Dir()
    Wend

I typed that function from memory and it turns out strFile will just be the filename without the path hence the changes on the FileCopy line.

You're having another problem of getting the event to fire but I have tested the above code in Access 2010 and it does work.
Avatar of MarkSnark1
MarkSnark1

ASKER

Thanks for trying. I cannot think of what might be wrong.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo