Results 1 to 10 of 10
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    Create an attachment buttom that will copy files to an specific location

    Hello everyone,

    I'm trying to create an attachment buttom to a predefined directory location (location would be based on the name of my field "Code_Id")

    First of all, I received the help to create a buttom that creates an specific folder named as my field "Code_Id"


    ************************************************** ***************
    https://www.accessforums.net/access/...tml#post302809


    Private Sub Createcmd_Click()

    Dim startPath As String
    Dim finalPath As String

    ' Enter starting path prefix
    startPath = "C:\Users\General\Desktop"

    ' Check to see if Code_Id entered
    If IsNull(Me.Code_Id) Then
    MsgBox "No Code ID entered"


    Else
    ' Build final path string
    finalPath = TrailingSlash(startPath) & Me.Code_Id
    ' Check to see if folder already exists
    If FolderExists(finalPath) Then
    MsgBox "The following path already exists:" & vbCrLf & finalPath
    Else
    ' If not, create it
    On Error GoTo err_check
    MkDir finalPath
    MsgBox "Successfully created folder: " & vbCrLf & finalPath
    On Error GoTo 0
    End If
    End If

    Exit Sub

    ' Error message to return if folder name is not valid err_check:



    Do you happen to know, the next.... based on the same of course...

    I would like to add some files to this pre-defined location (new folder created)



    I meant:

    1. Create a buttom named "Addfilescmd"
    2. Define an Event Addfilescmd_Onclick
    3. Open any directory (I have the code to do this "EscogeFichero"

    4 Instead (on my code) just to copy the root directory, I would like to copy the file and locate this one into the new location created

    Please see the code:


    Module "EscogeFichero"

    ************************************************** ******************************
    Option Compare Database
    Option Explicit
    Function EscogeFichero(Tipo As Integer) As String

    'Variables'

    Dim wzhwndOwner As Long
    Dim wzAppName As String
    Dim wzDlgTitle As String
    Dim wzOpenTitle As String
    Dim wzFile As String
    Dim wzInitialDir As String
    Dim wzFilter As String
    Dim wzFilterIndex As Long
    Dim wzView As Long
    Dim wzflags As Long
    Dim wzfOpen As Boolean
    Dim Ret As Long

    'On Error go to'


    On Error GoTo EscogeFichero_Err
    WizHook.Key = 51488399

    wzhwndOwner = 0&
    wzAppName = ""
    If Tipo = 1 Then
    wzDlgTitle = "Escoge fichero para guardar"
    Else
    wzDlgTitle = "Escoja fichero gráfico (Jpj,Gif etc) como fondo del Email"
    End If
    wzOpenTitle = "Escoja fichero"
    wzFile = String(255, Chr(0))
    wzInitialDir = CurrentProject.Path & "\"

    If Tipo = 1 Then
    wzFilter = "Cualquier fichero " _
    & "(*.*)"
    Else
    wzFilter = "Fichero Gráfico " _
    & "(*.jpg;*.gif;*.bmp)"
    End If
    wzFilterIndex = 1
    wzView = 1
    wzflags = 64
    wzfOpen = True


    Ret = WizHook.GetFileName(wzhwndOwner, _
    wzAppName, wzDlgTitle, wzOpenTitle, wzFile, _
    wzInitialDir, wzFilter, wzFilterIndex, _
    wzView, wzflags, wzfOpen)

    If Ret <> -302 Then
    EscogeFichero = wzFile
    Else
    EscogeFichero = ""
    End If


    EscogeFichero_Exit:
    Exit Function


    EscogeFichero_Err:


    MsgBox "Error nº " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
    "en procedimiento EscogeFichero de Módulo EscogeFichero", vbCritical, "Aviso de error"
    Resume EscogeFichero_Exit

    End Function

    ************************************************** ****************************

    And into the form a buttom named "Problemsupportcmd"

    Me.Problemsupporttxt = EscogeFichero(1) '1 es para cualquier tipo de ficheros
    CmdOpen_Click_Exit:
    Exit Sub


    CmdOpen_Click_Err:
    MsgBox "Error nº " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
    "en procedimiento CmdOpen_Click de Documento VBA Form_FrmMensaje", vbCritical, "Aviso de error"
    Resume CmdOpen_Click_Exit

    ************************************************** **********************

    Basically I want to create the attachment option but the directory will be related to new folder named as my field "Code_Id" located at the same form


    Thanks!!!!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I am not sure I understand what you are trying to do. If you want to move or copy files from one folder to another here is an example.
    https://www.accessforums.net/program...ugh-39179.html

  3. #3
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Just your idea is what I'm trying to do.... I performed a test but it shows an error

    Dim sourceFile As String, destinationFile As String
    Dim aFSO As Object
    sourceFile = Me.Problemsupporttxt
    '"C:\Users\General\Pictures\Logo.jpg"
    'original1: "C:\Test\Sub1"
    destinationFile = "C:\Users\General\Desktop"
    'original 2: "C:\Test\NewFolder"
    Set aFSO = CreateObject("Scripting.FileSystemObject")
    aFSO.CopyFolder sourceFile, destinationFile



    ​This is not copying the file

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    The code I used is a little misleading. sourceFile is actually a folder, as well as destinationFile.

    Consider the Method, CopyFolder
    aFSO.CopyFolder

    The following code I tested and it takes the contents of a folder named TextFiles and places the contents on the current user's desktop.
    Code:
    Dim sourceFolder As String, destinationFolder As String
    Dim aFSO As Object
    sourceFolder = "C:\Test\TextFiles"
    destinationFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop")
    Set aFSO = CreateObject("Scripting.FileSystemObject")
    aFSO.CopyFolder sourceFolder, destinationFolder

  5. #5
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Wow!!

    This is great!
    Would be possible to do this, but not all the folder, I meant just one file? how it should be changed?

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Edit: The destination needs to be the full path, including the folder and file path.
    so something like
    destinationFolder = CreateObject("WScript.Shell").SpecialFolders("Desk top") & "FileName.txt"

    Instead of CopyFolder you would use CopyFile. So
    Source = File
    and
    Destination = Folder & FileName.

  7. #7
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    You are right it works pretty good, just a quick question..... I would like the path destination will depend on the field Code_Id, how would it modified?

    Look at the code


    ************************************************** **

    Private Sub Attachcmd_Click()

    Dim sourceFolder As String, destinationFolder As String
    Dim aFSO As Object
    Dim Direccion As String
    'Dim Destination As String


    Direccion = Me.Problemsupporttxt


    sourceFolder = Direccion


    destinationFolder = "C:\Users\General\Resultado\ 'On this part of the path I want to add the information included into the field "Me.Code"


    Set aFSO = CreateObject("Scripting.FileSystemObject")
    aFSO.CopyFile sourceFolder, destinationFolder


    End Sub

    ************************************************** *********

    Thanks!!!!

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I am not understanding what you are trying to do and where you are stuck. Reading the code is not helping me to understand. Can you start from the beginning? Just say what you are trying to accomplish without providing examples of code. For instance, I have some files in a folder and I want to copy those files to a new folder on my desktop. I need to give the new folder a special name. The name of the folder I want to create is available in a field named, "Code_ID".

  9. #9
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    well the main idea of the app is the next:

    When the form is updated, automatically is also generated a new folder. it will be located on C:\Users\General\Desktop The new folder created is also named as the field "Code_Id".... all this part has been completed and works pretty fine.

    Now into the same form I added a command buttom named "Attachcmd", the idea is to attach information to the new folder created. (Any document) and everything is almost working

    Just need to fix the route:

    destinationFolder = "C:\Users\General\Desktop\ 'On this part of the path I want to add "Me.Code_ID"

    with this fix I know the information will be keeped into the folder with the reference needed

    I hope it would be a better explaination

    Thank you very much!!!!!


  10. #10
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    "C:\Users\General\Desktop\" & Me.Code_ID + "\"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 06-18-2013, 09:06 AM
  2. Replies: 23
    Last Post: 05-18-2012, 08:31 AM
  3. Copy files into specific folder
    By Jan22 in forum Access
    Replies: 12
    Last Post: 04-17-2012, 08:27 AM
  4. Import multiple files from one location to new tables
    By shmalex007 in forum Import/Export Data
    Replies: 1
    Last Post: 01-05-2012, 03:49 AM
  5. Attachment file location change
    By gary742 in forum Access
    Replies: 3
    Last Post: 03-22-2011, 12:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums