Results 1 to 14 of 14
  1. #1
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186

    Select a Folder to add the root to a textbox field

    Hi everyone!

    I want to add the full root of a folder to a textbox field but I am not sure what change to my code. Normally I use this code for select a file and it adds to my textbox the root of that file.... in this case I just want the root of the folfer where it is located example... (C:\Users\me\Desktop\Foldername\)

    This is the code normallly I use for files....

    '********************************************
    Function EscogeFicheroRuta(Tipo As Integer) As String


    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 GoTo EscogeFicheroRuta_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 = "Seleccionar Carpeta " _
    & "(*.*)"
    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
    EscogeFicheroRuta = wzFile
    Else
    EscogeFicheroRuta = ""
    End If


    EscogeFicheroRuta_Exit:
    Exit Function


    EscogeFicheroRuta_Err:


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

    End Function
    '****************************************

    Thanks in advance for the help!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Just find the last \ and use all the text before that position.
    InstrRev() would be your friend.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Another way is to use the built in FileDialog:
    https://www.iaccessworld.com/folder-...lder-get-path/
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Interesting example

    The only I have is that is gives me back a compilation error on the Fd As FileDialog
    Any idea why? or how solve it?

    Function SelectFolder() 'or Sub SelectFolder()
    Dim Fd As FileDialog 'it shows a messagebox with a compilation error type has not been defined by the user
    Set Fd = Application.FileDialog(msoFileDialogFolderPicker)
    With Fd
    .AllowMultiSelect = False
    .Title = "Please select folder"
    If .Show = True Then 'if OK is pressed
    Me.BackupFolder = .SelectedItems(1) 'write the selected folder in the textbox
    Else
    Exit Function 'click Cancel or X box to close the dialog
    End If
    End With
    Set Fd = Nothing
    End Function 'End Sub

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Look for missing references.
    I cannot remember what reference you need for that. Try googling for it.
    My thoughts were the least change to your existing code?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    You just have to add a reference to the MS Office library (MSO.dll).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Thank you both!!
    At the beginning was difficult to find the reference because I think it has not been added but I finally found it on the next root
    C:\Program Files\Microsoft Office\Root\VFS\ProgramFilesCommonX86\MicrosoftSha red\OFFICE16\MSO.dll

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    No. You look at the references list in the VBA window.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    @Welshgasman: that one is not usually in the list so you'd have to browse for it.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Really?, I have never had to browse for a file reference, just selected from the list.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    You're both right depending on the Access version.
    For example, IIRC its missing from Access 2010 but present in 365
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Here is what I have in 2007?
    Attached Thumbnails Attached Thumbnails ms office.PNG  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    I have Access 2010 and 2013 and the MS Office library isn't listed in either of them so had to browse .

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #14
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    @charly.csh
    I've only just read the code you used in post #1.
    That is one of the very rare times I've ever seen anyone post code using the hidden, undocumented Wizhook object and its members in the 20+ years it has been available
    Its not widely known about precisely because its hidden and undocumented...but it is very useful for certain tasks

    You may be interested in my article and example app about using Wizhook: https://www.isladogs.co.uk/wizhook/index.html
    It also contains links to other related articles both on my website and elsewhere

    By chance, I've also just posted the first in a series of Wizhook videos on YouTube: Wizhook: A Hidden (But Very Useful) Access Object - YouTube

    Anyway, for the benefit of others reading this thread, using Wizhook.GetFileName allows you to open a File...Browse dialog without needing to add a reference or use APIs for the purpose.
    When it first became available in Access 2000, it was a great improvement on what went before.

    Having said all that, I would now also recommend the use FileSystemObject as it is both much simpler to code and more versatile
    Last edited by isladogs; 11-26-2022 at 08:32 AM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Qubic root
    By inke01 in forum Access
    Replies: 2
    Last Post: 05-13-2020, 08:44 AM
  2. Replies: 6
    Last Post: 06-06-2019, 02:29 PM
  3. Create A Folder With Textbox Value
    By Eranka in forum Access
    Replies: 10
    Last Post: 06-25-2018, 09:02 AM
  4. FileDialog to select a file or a folder
    By mb4673 in forum Access
    Replies: 6
    Last Post: 12-12-2017, 02:06 AM
  5. Replies: 3
    Last Post: 09-02-2014, 06:45 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