I have an excel file that takes pasted part numbers and downloads the linked files to a local directory. I'd really like to do this in Access (2007). So the user doesn't have to use two tools to accomplish the task.
I have a table in Access that has the path and file name links to the server location available. I've tried looking for the answer, but am under a deadline to finish.
I would like to loop through the table download all files in the table. Does anyone have the code to do this readily available? Any help would be greatly appreciated!
Signed, totally clueless :)
Here is the excel vba code: - Public sPartNo As String
-
Public Rev As String
-
Public iLastRow As Long
-
Public sDownload As Integer
-
Public Test2 As String
-
-
-
Sub Last_Row()
-
-
Range("A1").Select
-
Range(Selection, Selection.End(xlDown)).Select
-
iLastRow = Selection.Rows.Count
-
-
End Sub
-
-
Sub GetDrawing_Link()
-
Dim iPartNoCol As Integer 'column that contains the part number
-
Dim iRevCol As Integer 'column that contains the revision
-
Dim iFirstRow As Long 'first row to process
-
-
Dim strQuery As String
-
-
Dim varRowToProcess As Long 'row that is currently being processed
-
Dim sdir As String
-
Dim Count, Count2, Count3 As Long
-
-
Dim varCellTest, varLinkToUse As String
-
-
sDownload = MsgBox("Do you want to download the files to you computer?", 4, "Download Files to Computer")
-
-
iPartNoCol = 1
-
iRevCol = 2
-
iFirstRow = 2
-
Count2 = 0
-
-
Last_Row
-
-
'Create C:\tempdwgs directory and delete all files
-
If Dir("c:\tempdwgs", vbDirectory) <> "tempdwgs" Then
-
MkDir ("c:\tempdwgs")
-
End If
-
-
If Dir("C:\tempdwgs\" & "*.*") = "" = False Then
-
Kill "C:\tempdwgs\*.*"
-
End If
-
-
For varRowToProcess = iFirstRow To (iLastRow)
-
-
sPartNo = Trim(ActiveSheet.Cells(varRowToProcess, iPartNoCol).Value)
-
-
Application.ScreenUpdating = False
-
-
sSQL = "select locationpath, imgfilename"
-
sSQL = sSQL + " from DOC_Image"
-
sSQL = sSQL + " WHERE partnumber = '" & sPartNo & "' AND partrev = '" & Rev & "'"
-
-
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN="";Description="";SERVER="";UID=Shareuser;PWD=asdf;DATABASE=""", Destination:=Range("I1"))
-
.Sql = sSQL
-
.FieldNames = False
-
.RefreshStyle = xlOverwriteCells
-
.RowNumbers = False
-
.FillAdjacentFormulas = False
-
.RefreshOnFileOpen = False
-
.HasAutoFormat = True
-
.BackgroundQuery = False
-
.TablesOnlyFromHTML = True
-
.Refresh BackgroundQuery:=False
-
.SavePassword = False
-
.SaveData = True
-
End With
-
Folder = Range("I1").Value
-
Filename = Range("J1").Value
-
Link = Folder & "\" & Filename
-
Application.DisplayAlerts = False
-
-
-
If Link <> "\" Then
-
ActiveSheet.Cells(varRowToProcess, iPartNoCol).Select
-
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
-
Link
-
If sDownload = 6 Then
-
FileCopy Link, "c:\tempdwgs\" & Filename
-
End If
-
End If
-
-
Next varRowToProcess
-
-
If sDownload = 6 Then
-
Shell "Explorer.exe c:\tempdwgs\"
-
End If
-
-
End Sub
-
-
Sub Get_Rev()
-
-
Application.ScreenUpdating = False
-
-
sSQL = "select prtrev"
-
sSQL = sSQL + " from prtdaily"
-
sSQL = sSQL + " where prtno = '" & sPartNo & "'"
-
-
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN="";Description="";SERVER="";UID="";PWD="";DATABASE=""", Destination:=Range("I1"))
-
.Sql = sSQL
-
.FieldNames = False
-
.RefreshStyle = xlOverwriteCells
-
.RowNumbers = False
-
.FillAdjacentFormulas = False
-
.RefreshOnFileOpen = False
-
.HasAutoFormat = True
-
.BackgroundQuery = False
-
.TablesOnlyFromHTML = True
-
.Refresh BackgroundQuery:=False
-
.SavePassword = False
-
.SaveData = True
-
End With
-
Rev = Range("I1").Value
-
Application.DisplayAlerts = False
-
-
End Sub
3 1683
When posting over 100 lines of code, its generally a good idea to point out which lines you might want someone to look at.
For copying files, I like to use the filesystemobject. Its quite versatile, and easy to use. - Dim oFSO as FileSystemObject 'Need reference to Windows Script Host Object Model, or use late binding
-
set oFSO=new FileSystemObject
-
oFSO.CopyFile sSourcePath,sDestPath
-
Set oFSO=nothing
vanlash,
You don't make clear whether the files are on your domain or not. If they are you can use the filesystemobject, as TheSMileyCoder suggested. If not, you're probably going to want to use FTP to download those files.
If you know FTP you could use Access to create some text script files with .bat extensions and then execute them from within the VBA. But also there's lot of discussions online about FTP from VBA. Here's one that might get you started quickly: http://www.access-programmers.co.uk/...d.php?t=178371
Jim
zmbd 5,501
Expert Mod 4TB
open a record set on your files
provide the full path for both source and destination FileCopy Statement
Do ... Until rs.eof
If you need to move the files...
I still prefer the copy first, then verify the file in the new location, then delete the file from the old...
OR
if you just want to move the files in one go:
basically the same as the first
use the Name statement
instead if filecopy.
No need for extra library references nor any fancy codeing
this is old school BASIC (^_^)
-z
Sign in to post your reply or Sign up for a free account.
Similar topics
by: CodeMotion |
last post by:
I have access to an internet directory and files will be placed in
this directory periodically. I am writing a service to poll that
directory and download the files for processing. I have figured...
|
by: ReidarT |
last post by:
I want to copy files in directory to another location like
c:\dir1\*.* to f:\dir2
Do I need to copy file by file or can I just copy the whole directory
regards
reidarT
|
by: tanyali |
last post by:
using php5, I download files :
******** downloadfile.php
$fileContent = @mysql_result($result1,$i,"gdata");
...
|
by: deciacco |
last post by:
I'm trying to write a utility that will compare a local directory and
it's subdirectories with a directory on an ftp server.
The .net directory and file classes could be useful on the local side,...
|
by: nathj |
last post by:
Hi,
I am working on a system, as you may have seen from my other posts, that allows members to download files. When they download a file I want to store the user ID and the file ID in a table...
|
by: =?Utf-8?B?UHVyZSBIZWFydA==?= |
last post by:
hi
i need the code to move files from directory to another directory on sam
local machine or to a network path, thank you.
--
Ammar S. Mitoori
IT Head QIMCO Co.
Tel : +9744831199
Mobile :...
|
by: David C |
last post by:
I have an ASP.Net web site that does some file system folder access. One of
the things I am doing is counting the # of files in a passed directory to
determine if I show or hide something on the...
|
by: samvb |
last post by:
hi guys,
i am lookin to creatin a local site. i want them to download files to thier local computer from the server. how can i do that? the server is ftp.
|
by: robain |
last post by:
I am looking for an isolated piece of code that uses XmlHttpRequest/JavaScript to download files from a (specified path on a) server to local machine. The browser on the local machine...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |