By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

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" <cl************@columbus.rr.com> wrote in message
news:d0**************************@posting.google.c om...
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

Nov 13 '05 #2

P: n/a
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!
Nov 13 '05 #3

P: n/a
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
Nov 13 '05 #4

P: n/a
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" <cl************@columbus.rr.com> wrote in message
news:d0**************************@posting.google.c om...
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

Nov 13 '05 #5

P: n/a
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

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

This discussion thread is closed

Replies have been disabled for this discussion.