Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Drag and Drop from Windows Explorer to copy files from 1 directory to another

20 views
Skip to first unread message

IdeaMan

unread,
Aug 20, 2004, 11:57:22 AM8/20/04
to
Windows 2000
Access 97
I am working on an issue tracking DB, where I need to link (not attach
due to size)screen prints of various system errors.

I have created a public folder on a network drive to store these
images, under the assumption that no one will originally save them to
that location. To resolve this, I need to copy the file to this
location without possibility of user error in selecting the correct
folder (the DB is to be used by many people spanning a great
distance). I am using the "API: Drag and Drop from Explorer" code
found at http://www.mvps.org/access/api/api0032.htm and have
successfully implemented it, where it displays the full local/original
path to the file in the listbox on the form you create to house the
code. This is a perfect (and user friendly) interface to select the
file itself and even allows me to record the original path to where
the file was saved, but have been unable to find a way to pass this
file name/path to a FileCopy command or even the ahtCommonFileOpenSave
dialog box.

Am I overlooking any better, simpler, or more efficient way of doing
this-or is it even possible? Out of frustration, the code that I have
been experimenting with has become rather incomprehensible so I did
not post it with this message. I have searched newsgroups high and low
for a solution over the last few days and in turn have said goodbye to
a few more hairs on my head.

Any help or examples anyone could provide would be greatly appreciated
as I need to resolve this issue quickly and it would also help me
better understand how Access code works.

Thanks!
Michael

Terry Kreft

unread,
Aug 20, 2004, 12:12:14 PM8/20/04
to

If you look at the example from the Access Web and particularly at the
function sDragDrop in the module you see a line
.RowSource = strOut

the strOut variable contains the string you are looking for to pass (or
parse before passing) to FileCopy.

If you for example change the code
With Forms!frmDragDrop!lstDrop
.RowSourceType = "Value List"
.RowSource = strOut
Forms!frmDragDrop.Caption = "DragDrop: " & _
.ListCount & _
" files dropped."
End With

to
Debug.Print strOut
With Forms!frmDragDrop!lstDrop
.RowSourceType = "Value List"
.RowSource = strOut
Forms!frmDragDrop.Caption = "DragDrop: " & _
.ListCount & _
" files dropped."
End With

You'll notice that if you drag 'n' drop a single file into the list box that
files path will also appear in the debug window.

If you drag a few files into the list box then a semi-colon separated list
of the file names appears in the debug window.


--
Terry Kreft
MVP Microsoft Access


"IdeaMan" <clarine...@columbus.rr.com> wrote in message
news:d0c1a31a.04082...@posting.google.com...

IdeaMan

unread,
Aug 25, 2004, 5:53:01 PM8/25/04
to
Terry-
Thank you for your prompt response. I truly appreciate your help.

Just a couple more questions...I have the code working, and it stores
the displayed path in a table after also extracting the filename (to be
used as a "link" to be used later in the apiShellExecute function to
open the linked file). I see where you mention that multiple files can
be dragged to the listbox on the form, and this works just fine as well,
all paths being seperated by a ";". I would like to add this
functionality to the form (to add more than just one file), but when
executed the code only stores the first file's path in the table, and
neither the filecopy or the filename parsing functions work because I am
not sure where to place these within the function. Could you provide
any insight? The code is posted below. I only started using Access
about 4 weeks ago, so I apologize for any glaring errors! ;) Thanks in
advance for your help! :)


Michael


'code from http://www.mvps.org/access/api/api0032.htm,_
'"API: Drag and Drop from Explorer"
'************* Code Start *************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'

Sub sDragDrop(ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long)

Dim lngRet As Long, strTmp As String, intLen As Integer
Dim lngCount As Long, i As Long, strOut As String
Dim filename As String
Dim infilename As Long
Dim dest As String
Const cMAX_SIZE = 255
On Error Resume Next
If Msg = WM_DROPFILES Then
strTmp = String$(255, 0)
lngCount = apiDragQueryFile(wParam, &HFFFFFFFF, _
strTmp, Len(strTmp))
For i = 0 To lngCount - 1
strTmp = String$(cMAX_SIZE, 0)
intLen = apiDragQueryFile(wParam, i, strTmp, _
cMAX_SIZE)
strOut = strOut & Left$(strTmp, intLen) & ";"
Next i
strOut = Left$(strOut, Len(strOut) - 1)
Call sapiDragFinish(wParam)
Debug.Print strOut
With Forms!Drag_Files_Here!lstDrop 'modified _
'form name from frmDragDrop


.RowSourceType = "Value List"
.RowSource = strOut

Forms!Drag_Files_Here.Caption = _
"Attached File(s): " & .ListCount
infilename = Len(strOut)
filename = Right$(strOut, infilename - _
InStrRev(strOut, "\"))
Forms!Drag_Files_Here!Filenames = filename
dest = "c:\" & filename
Forms!Drag_Files_Here!link = dest
FileCopy strOut, dest
Forms!Drag_Files_Here!Issue_ID = _
Forms!Add_New_Issue!Issue_ID
End With
Else
lngRet = apiCallWindowProc( _
ByVal lpPrevWndProc, _
ByVal hwnd, _
ByVal Msg, _
ByVal wParam, _
ByVal lParam)
End If
End Sub


'other functions used:
'
'
'
Option Compare Database
Option Explicit
Function ParsePath(strPath As String, lngPart As Integer) As String

' This procedure takes a file path and returns
' the path (everything but the file name), the
' file name, the drive letter, or the file extension,
' depending on which constant was passed in.

Dim lngPos As Long
Dim strPart As String
Dim blnIncludesFile As Boolean
Dim intLenofExt As Integer
' Check that this is a file path.
' Find the last path separator.
lngPos = InStrRev(strPath, "\")
'If not fullstop add one
If InStr(strPath, ".") = 0 Then strPath = strPath & "."
' Determine whether portion of string after last _
'backslash
' contains a period.

blnIncludesFile = InStrRev(strPath, ".") > lngPos

If lngPos > 0 Then
Select Case lngPart
' Return file name.
Case 1
If blnIncludesFile Then
intLenofExt = Len(Mid(strPath, _
InStrRev(strPath, ".") + 1))
strPart = Right$(strPath, _
Len(strPath) - lngPos)
' do not include the _
'file ext in the filename
strPart = Left(strPart, _
Len(strPart) - (intLenofExt + 1))
Else
strPart = Right$(strPath, _
Len(strPath) - lngPos)
End If
' Return path.
Case 2
If blnIncludesFile Then
strPart = Left$(strPath, lngPos)
Else
strPart = strPath
End If
' Return drive.
Case 3
strPart = Left$(strPath, 3)
' Return file extension.
Case 4
If blnIncludesFile Then
' Take three characters and period.
strPart = Mid(strPath, _
InStrRev(strPath, "."), 4)
Else
strPart = ""
End If
Case Else
strPart = ""
End Select
End If
ParsePath = strPart

ParsePath_End:
Exit Function
End Function

Public Function InStrRev( _
StringCheck As String, _
StringMatch As String, _
Optional Start As Long = -1, _
Optional Compare As Integer = 2) _
As Long
'-------------------------------------------------------'----
' Inputs: String to check,
' match string,
' optional starting position (default = -1),
' optional string compare _
'value (default vbDatabaseCompare)
' Outputs: Position of match string, starting from _
'the end
' Original code by: John L. Viescas 15-Nov-2001
' Revised by: Dirk Goldgar 21-Jan-2002
' Last Revision: Dirk Goldgar 21-Jan-2002
' ** Duplicates the functionality of the VB 6 _
'INSTRREV function.
'-------------------------------------------------------'----
Dim lngS As Long, lngI As Long
Dim lngLenC As Long, lngLenM As Long

' Do some initial checks
If (Compare < 0) Or (Compare > 2) Then
Err.Raise 5
Exit Function
End If
If Len(StringCheck) = 0 Then
InStrRev = 0
Exit Function
End If
If Len(StringMatch) = 0 Then
InStrRev = Start
Exit Function
End If
If Start > Len(StringCheck) Then
InStrRev = 0
Exit Function
End If
If Len(StringMatch) > Len(StringCheck) Then
InStrRev = 0
Exit Function
End If

' OK, have some work to do!
lngS = Start
lngLenC = Len(StringCheck)
lngLenM = Len(StringMatch)
If lngS = -1 Then lngS = lngLenC
lngS = (lngS - lngLenM) + 1
' Set default not found
InStrRev = 0
' Now loop to see if we can find it
For lngI = lngS To 1 Step -1
If StrComp(Mid$(StringCheck, lngI, lngLenM), _
StringMatch, Compare) = 0 _
Then
InStrRev = lngI
Exit For
End If
Next lngI

End Function


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

IdeaMan

unread,
Aug 25, 2004, 7:15:59 PM8/25/04
to


Michael

.RowSourceType = "Value List"
.RowSource = strOut

Terry Kreft

unread,
Aug 26, 2004, 9:38:16 AM8/26/04
to
I take it you are using a bound list? If that is the case then I would
expect it to only store one filename in the underlying field.

If you need to store all the filenames you'll need to iterate throught the
list of filenames and store them.


--
Terry Kreft
MVP Microsoft Access


"IdeaMan" <clarine...@columbus.rr.com> wrote in message
news:d0c1a31a.04082...@posting.google.com...

IdeaMan

unread,
Aug 26, 2004, 9:52:59 AM8/26/04
to
Terry-
Thanks for your response. I am using a bound list to store the
filename. Can you assist me on how I should set up the code to include
each file in the following tasks (from my code)? This is where I am
really stuck...

filecopy
parse filename (after seperating each files' string-seperated by ";")
after storing record (bound list), go to new record (for the path
table)to enter the next file path

I tried grouping these actions together within the same for...next
statement and have re-arranged the code so many times I am lost...


Thanks again for your help-I really appreciate it!

Michael

0 new messages