Darren - Active Billing
darren at activebilling.com.au
Thu Jan 14 16:23:03 CST 2010
Hi Jürgen Wow this is great and very detailed - many thanks I will work on this again tonight - I'll let you know how it turns out Again - Many many thanks, you've put in a lot of effort on my behalf - I truly am most grateful. :-) Darren -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Jurgen Welz Sent: Friday, 15 January 2010 6:10 AM To: accessd at databaseadvisors.com Subject: Re: [AccessD] A2K:Get file name after drag and drop_SecondSend I copied and pasted the code from the top listbox at http://digitalpbk.blogspot.com/2006/12/drag-n-drop-files-from-explorer-to-vb.htm l directly into a new module. To the module code, I added an additional private variable: Private mfrm as Form I modified the EnableDragDrop procdure to initialize the above variable. To do so I added a form parameter to the enable procedure as follows: Public Sub EnableDragDrop(ByVal hwnd As Long, frm As Form) DragAcceptFiles hwnd, 1 HookForm (hwnd) Set mfrm = frm End Sub and also set the form variable to nothing in the DisableDragDrop procedure The Dropped procedure in the module was modified to return the file name and path to the subform by passing it to a public GotADrop procedure on the subform: Public Sub Dropped(ByVal HDROP As Long) Dim strFilename As String * 511 Call DragQueryFile(HDROP, 0, strFilename, 511) 'Get the filename. 'Debug.Print TrimNulls(strFilename) mfrm.GotADrop TrimNulls(strFilename) End Sub My form code, and the form in question is always a subform that is nothing more than a listbox that displays a list of files and folders based on the parent form: Private Sub Form_Load() EnableDragDrop Me.hwnd, Forms(Me.Parent.Name).sfrmDocumentList.Form End Sub Public Sub GotADrop(ByVal strfile As String) MsgBox strfile End Sub The subform is placed on various parent forms such as ContactDocs, EstimateDocs, ProjectDocs, EmployeeDocs... The parent form sets the subform to display files and folders in a path determined by the table and primary key of the record. The parent form allows the user to select a type of file from a drop down list for generation. For example, the employee form would allow creation of a Word doc letter for a discipline notice, raise or transfer... The Estimate form would allow generation of a tender, request for information, transmittal... In any event, the subform is aware of the path in which to create a file as it displays files in the path and creates a path as required. Although the GotADrop procedure above only pops a message box, the code provides for copying a file to the target path. I use an API copy procedure that provides an optional overwrite parameter: Private Declare Function CopyFileA Lib "kernel32" (ByVal ExistingFileName As String, _ ByVal NewFileName As String, ByVal FailIfExists As Long) As Long Public Function Copy(FileSrc As String, FileDst As String, Optional NoOverWrite As Boolean = True) _ As Boolean On Error GoTo ErrorHandler Copy = CopyFileA(FileSrc, FileDst, NoOverWrite) = 1 ExitRoutine: On Error Resume Next Exit Function ErrorHandler: With Err Select Case .Number Case Else MsgBox .Number & vbCrLf & .Description, vbInformation, "Error - Copy" End Select End With 'Resume 0 Resume ExitRoutine End Function I didn't see a trimNulls procedure in the sample code but use it in my version: Public Function TrimNulls(startstr As String) As String TrimNulls = Left$(startstr, lstrlenW(StrPtr(startstr))) End Function As the drop procedure allows dropping of a folder, I also have a copy folder (and subfolders) procedure, though I've recently been adopting a shelled robocopy command. I test for directory when not moving single files: If (GetAttr(strPath & strFolder) And vbDirectory) = vbDirectory Then For copying individual files, I parse out the last '\' with instrRev an mid$ from that point on from the source file name returned to the form GotADrop procedure. I don't have any problems relating to hanging of the application and am unaware of any memory leak issues. I have 65 users running in a virtual server (Windows 2003 Server) environment. I believe we have 2 physical servers with 8 gigs each for all users. Ciao Jürgen Welz Edmonton, Alberta jwelz at hotmail.com > From: darren at activebilling.com.au > To: accessd at databaseadvisors.com > Date: Fri, 15 Jan 2010 01:04:17 +1100 > Subject: Re: [AccessD] A2K:Get file name after drag and drop_SecondSend > > Hi Jürgen > > I have played about with this code and having a lot of difficulties getting it > to run nicely. It hangs, memory hogging constantly and regularly need to CTRL > ALT DEL to close Access etc > > If it's not too much trouble, can I please see a sample of the thing you speak > about in your previous post? > > Many thanks in advance > > Darren > > > -----Original Message----- > From: accessd-bounces at databaseadvisors.com > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Jurgen Welz > Sent: Friday, 01 January 2010 4:17 AM > To: accessd at databaseadvisors.com > Subject: Re: [AccessD] A2K:Get file name after drag and drop_SecondSend > > > It was the link in Michael's post. > > Ciao Jürgen Welz Edmonton, Alberta jwelz at hotmail.com > > > > > From: darren at activebilling.com.au > > To: accessd at databaseadvisors.com > > Date: Sat, 26 Dec 2009 20:14:59 +1100 > > Subject: Re: [AccessD] A2K:Get file name after drag and drop_SecondSend > > > > Hi Jurgen > > When you say great code are you referring to the link in Michael's post below > or > > was there some code or example in your post I can't see? > > > > Many thanks > > > > Darren > > > > > > -----Original Message----- > > From: accessd-bounces at databaseadvisors.com > > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Jurgen Welz > > Sent: Wednesday, 23 December 2009 8:46 AM > > To: accessd at databaseadvisors.com > > Subject: Re: [AccessD] A2K:Get file name after drag and drop_SecondSend > > > > > > Great Code. Works well in Access 2003. Properties on the VBA Editor Help -> > > About screen in this version of Access shows VB 6.3. I added the form code to > a > > sub form Filelist common to several forms in an application. It stores the > full > > file path and name in the strFilename variable of the Public Dropped procedure > > as written. > > > > > > > > This procedure will allow me to directly copy files to one or more of the > > folders displayed in my file list subform using file procedures in VBA. Very > > Nice! > > > > Ciao > > > > Jürgen Welz > > > > Edmonton, Alberta > > > > jwelz at hotmail.com > > _________________________________________________________________ > Windows Live: Keep your friends up to date with what you do online. > http://go.microsoft.com/?linkid=9691815 > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com _________________________________________________________________ -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com