New Folder in Existing Project Folder (1 Viewer)

RasmusElkjaer

New member
Local time
Today, 13:03
Joined
Oct 6, 2021
Messages
3
Hey Everyone

I am Currently working on a Access warranty Database, From a Excel Database, we are Folders for each Project And in that folder we have a New folder for each Claim we get so we can put relevant files in there.

i have made some code to locate the project file, but is it possible so every time i make a new claim in my form i can link to that file path and then make a new folder for the current Claim nr?

currently i have made a code with Mkdir, so it takes my project No and Name, and make a folder if there isent one, it work perfekt, but some ppl would like to point were in the project the files should be saved any ideas how to do so? tried for some time now and googled alot :)

have a nice day!

Kind regards Rasmus
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:03
Joined
Feb 19, 2002
Messages
42,970
I'm not sure I understand the question. I thought the folder names were dictated by the project and claim. Now you are saying you want the user to choose a folder? Won't that confuse people?
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 05:03
Joined
Oct 29, 2018
Messages
21,357
Hi. Welcome to AWF!

Maybe you can give us some examples of the paths your users might want to create?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:03
Joined
Feb 19, 2002
Messages
42,970
This is the code to open the file dialog to either choose a file or a directory. But in your situation, I don't think it is correct for users to choose their own directories. Maybe for other tasks or maybe to set up a default when the app is installed. So, here's the code.
Code:
Option Compare Database
Option Explicit

Public Function fChooseFile()
 
   ' Requires reference to Microsoft Office 11.0 Object Library.
 
   Dim fDialog As Office.FileDialog
   Dim varFile As Variant
 
   ' Set up the File Dialog.
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
 
   With fDialog
 
      ' Allow user to make multiple selections in dialog box
      .AllowMultiSelect = False
            
      ' Set the title of the dialog box.
      .Title = "Please select one file"
 
      'starting location
      .InitialFileName = CurrentProject.path
      
      ' Clear out the current filters, and add our own.
      .Filters.Clear
''''      .Filters.Add "Excel ", "*.XLSX"
      .Filters.Add "Access Databases", "*.ACCDB, *.MDB"
''''      .Filters.Add "Access Projects", "*.ADP"
      .Filters.Add "All Files", "*.*"
 
      ' Show the dialog box. If the .Show method returns True, the
      ' user picked at least one file. If the .Show method returns
      ' False, the user clicked Cancel.
      If .Show = True Then
         'Loop through each file selected and add it to our list box.
         For Each varFile In .SelectedItems
            fChooseFile = varFile
''''            Me.FileList.AddItem varFile
         Next
        
      Else
         MsgBox "You clicked Cancel in the file dialog box."
      End If
   End With

End Function

Public Function fChooseDirectory()

    ' requires a reference to the Office xx Object library
    'Declare a variable as a FileDialog object.
    'Dim fd As FileDialog

   '''' Const msoFileDialogFolderPicker = 4 'use for late binding
    
    Dim fd As Object
    
    'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)

    'Declare a variable to contain the path
    'of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant

    'Use a With...End With block to reference the FileDialog object.
    With fd

        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the action button.
        If .Show = -1 Then

            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems

                'vrtSelectedItem is a String that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example simply displays the path in a message box.

                'Only one item will be returned since the file dialog is a folder picker
                'MsgBox "The path is: " & vrtSelectedItem
                fChooseDirectory = vrtSelectedItem
                Exit Function
            Next vrtSelectedItem
        'The user pressed Cancel.
        Else
        End If
    End With

    'Set the object variable to Nothing.
    Set fd = Nothing
    fChooseDirectory = "Error - nothing chosen"
End Function
 

RasmusElkjaer

New member
Local time
Today, 13:03
Joined
Oct 6, 2021
Messages
3
thank you all i will look more in to the linked code i got it to work as i wanted with this code for the project
Code:
Private Sub DrawingLink_Click()
  Dim f As Object
  Dim strFile As String
  Dim strFolder As String
  Dim varItem As Variant

  Set f = Application.FileDialog(4)
  f.AllowMultiSelect = False
  If f.Show Then
    For Each varItem In f.SelectedItems
        strFile = Dir(varItem)
        strFolder = Left(varItem, Len(varItem) - Len(strFile))
        MsgBox "Folder: " & strFolder & vbCrLf & _
            "File: " & strFile
        Me.MainWarrantyfolder = strFolder
     Next
  End If
  Set f = Nothing
 
End Sub
and this code when in the claim
Code:
Private Sub Create_ViewFolder_Click()

Dim strPath As String
strPath = Me.MainWarrantyfolder
                    If Len(Dir(strPath, vbDirectory)) = 0 Then
                       MkDir strPath
                     End If
                     'dir henviser til eksisteren folder hvis der ingen er laver MKdir en ny folder

strPath = Me.MainWarrantyfolder & "\" & "NCR" & Me.GlobalNCRNo
                    If Len(Dir(strPath, vbDirectory)) = 0 Then
                       MkDir strPath
                
                     End If
                     'dir henviser til eksisteren folder hvis der ingen er laver MKdir en ny folder
                    
                     Me.ClaimFolder = strPath
                    
                     Application.FollowHyperlink Me.ClaimFolder
                                

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:03
Joined
Oct 29, 2018
Messages
21,357
Congratulations! Good luck with your project.
 

Users who are viewing this thread

Top Bottom