InStr and StrReverse

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imrosie
    New Member
    • May 2007
    • 222

    InStr and StrReverse

    Hello (from a newbie),


    I have an image database that pulls in a copy of a file (stores the link in database). The image shows up in my subform. I then show the name of file in a control called image description, however, it shows the entire link:
    D:\imageDogs\Ch estertheDog.jpg

    I'm looking for good example code for StrRevers (InStr)J, so I can somehow reverse the string, cut off the 'ChestertheDog. jpg and display only the ChestertheDog in the control. I also have another control box which I'd like the '.jpg' portion to go to.

    Has anyone done something like this? Help...I've been playing around with samples from the Web and nothings working. thanks

    Rosie
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Originally posted by imrosie
    Hello (from a newbie),


    I have an image database that pulls in a copy of a file (stores the link in database). The image shows up in my subform. I then show the name of file in a control called image description, however, it shows the entire link:
    D:\imageDogs\Ch estertheDog.jpg

    I'm looking for good example code for StrRevers (InStr)J, so I can somehow reverse the string, cut off the 'ChestertheDog. jpg and display only the ChestertheDog in the control. I also have another control box which I'd like the '.jpg' portion to go to.

    Has anyone done something like this? Help...I've been playing around with samples from the Web and nothings working. thanks

    Rosie
    Hi!

    Having dealed with a similar issue on batch file renaming some time ago I have written Class "FileFullPa th". Hereby I attach the code.

    Class module "FileFullPa th":

    Code:
    Dim strFilePath As String, strFileName As String, strFileExt As String
    
    Public Property Get Path() As String
        Path = strFilePath
    End Property
    
    Public Property Let Path(ByVal strNewValue As String)
        strFilePath = strNewValue
    End Property
    
    Public Property Get FileName() As String
        FileName = strFileName
    End Property
    
    Public Property Let FileName(ByVal strNewValue As String)
        strFileName = strNewValue
    End Property
    
    Public Property Get Extension() As String
        Extension = strFileExt
    End Property
    
    Public Property Let Extension(ByVal strNewValue As String)
        strFileExt = strNewValue
    End Property
    
    Public Property Get FullName() As String
    
        With Me
            FullName = .Path & "\" & .FileName & "." & .Extension
        End With
        
    End Property
    
    Public Property Let FullName(ByVal strNewValue As String)
    
        With Me
            .Path = CutSubString(strNewValue, "\")
            .FileName = CutSubString(strNewValue, ".")
            .Extension = strNewValue
        End With
        
    End Property
    
    Private Function CutSubString(ByRef strInput As String, _
                                  ByVal strTerminator As String) As String
    
        Dim intNewPos As Integer, intPos As Integer
    
        intNewPos = 0
        Do
            intPos = intNewPos
            intNewPos = InStr(intPos + 1, strInput, strTerminator, vbTextCompare)
        Loop Until intNewPos = 0
        CutSubString = Left(strInput, intPos - 1)
        strInput = Right(strInput, Len(strInput) - intPos)
    
    End Function
    Form module:

    Code:
    Private Sub FileLink_AfterUpdate()
    
        Dim objFileLink As New FileFullPath
        
        With objFileLink
            .FullName = Me![FileLink]
            Me![Path] = .Path
            Me![Name] = .FileName
            Me![Extension] = .Extension
        End With
        
        Set objFileLink = Nothing
        
    End Sub

    Comment

    • imrosie
      New Member
      • May 2007
      • 222

      #3
      Originally posted by FishVal
      Hi!

      Having dealed with a similar issue on batch file renaming some time ago I have written Class "FileFullPa th". Hereby I attach the code.

      Class module "FileFullPa th":

      Code:
      Dim strFilePath As String, strFileName As String, strFileExt As String
      
      Public Property Get Path() As String
          Path = strFilePath
      End Property
      
      Public Property Let Path(ByVal strNewValue As String)
          strFilePath = strNewValue
      End Property
      
      Public Property Get FileName() As String
          FileName = strFileName
      End Property
      
      Public Property Let FileName(ByVal strNewValue As String)
          strFileName = strNewValue
      End Property
      
      Public Property Get Extension() As String
          Extension = strFileExt
      End Property
      
      Public Property Let Extension(ByVal strNewValue As String)
          strFileExt = strNewValue
      End Property
      
      Public Property Get FullName() As String
      
          With Me
              FullName = .Path & "\" & .FileName & "." & .Extension
          End With
          
      End Property
      
      Public Property Let FullName(ByVal strNewValue As String)
      
          With Me
              .Path = CutSubString(strNewValue, "\")
              .FileName = CutSubString(strNewValue, ".")
              .Extension = strNewValue
          End With
          
      End Property
      
      Private Function CutSubString(ByRef strInput As String, _
                                    ByVal strTerminator As String) As String
      
          Dim intNewPos As Integer, intPos As Integer
      
          intNewPos = 0
          Do
              intPos = intNewPos
              intNewPos = InStr(intPos + 1, strInput, strTerminator, vbTextCompare)
          Loop Until intNewPos = 0
          CutSubString = Left(strInput, intPos - 1)
          strInput = Right(strInput, Len(strInput) - intPos)
      
      End Function
      Form module:

      Code:
      Private Sub FileLink_AfterUpdate()
      
          Dim objFileLink As New FileFullPath
          
          With objFileLink
              .FullName = Me![FileLink]
              Me![Path] = .Path
              Me![Name] = .FileName
              Me![Extension] = .Extension
          End With
          
          Set objFileLink = Nothing
          
      End Sub

      All I can say is WOW! FishVal.....Ire ad thru it and I never expected to find something that seems so complete....I'm off to give this a try...thanks so much. I'll be back with the results.

      Rosie

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by imrosie
        Hello (from a newbie),


        I have an image database that pulls in a copy of a file (stores the link in database). The image shows up in my subform. I then show the name of file in a control called image description, however, it shows the entire link:
        D:\imageDogs\Ch estertheDog.jpg

        I'm looking for good example code for StrRevers (InStr)J, so I can somehow reverse the string, cut off the 'ChestertheDog. jpg and display only the ChestertheDog in the control. I also have another control box which I'd like the '.jpg' portion to go to.

        Has anyone done something like this? Help...I've been playing around with samples from the Web and nothings working. thanks

        Rosie
        To simply parse the File Path, and return only the Base File Name without the Extension, only requires a couple of lines of code. Maybe you can incorporate this into your code, if you so desire:
        [CODE=vb]Dim strFilePath As String

        strFilePath = "D:\imageDogs\C hestertheDog.jp g" 'Absolute File Path

        'File Name with Extension (.jpg)
        strFilePath = Right$(strFileP ath, Len(strFilePath ) - InStrRev(strFil ePath, "\"))strFilePat h = Left$(strFilePa th, Len(strFilePath ) - 4) ' Base File Name
        Debug.Print strFilePath 'see OUTPUT below[/CODE]
        OUTPUT:
        Code:
        ChestertheDog

        Comment

        • MikeTheBike
          Recognized Expert Contributor
          • Jun 2007
          • 640

          #5
          Hi

          Originally posted by imrosie
          Hello (from a newbie),


          I have an image database that pulls in a copy of a file (stores the link in database). The image shows up in my subform. I then show the name of file in a control called image description, however, it shows the entire link:
          D:\imageDogs\Ch estertheDog.jpg

          I'm looking for good example code for StrRevers (InStr)J, so I can somehow reverse the string, cut off the 'ChestertheDog. jpg and display only the ChestertheDog in the control. I also have another control box which I'd like the '.jpg' portion to go to.

          Has anyone done something like this? Help...I've been playing around with samples from the Web and nothings working. thanks

          Rosie
          Does this help ?

          Code:
          Sub test()
              Dim Temp As String
              Dim FName As String
              Dim Ext As String
              Temp = "D:\imageDogs\ChestertheDog.jpg"
          
              Ext = Mid(Temp, InStrRev(Temp, ".") + 1)
          
              FName = Left(Temp, InStrRev(Temp, ".") - 1)
              FName = Mid(FName, InStrRev(Temp, "\") + 1)
              
              MsgBox "File Name = " & FName
              MsgBox "Extention = " & Ext
              
          End Sub
          MTB

          Comment

          • imrosie
            New Member
            • May 2007
            • 222

            #6
            Originally posted by ADezii
            To simply parse the File Path, and return only the Base File Name without the Extension, only requires a couple of lines of code. Maybe you can incorporate this into your code, if you so desire:
            [CODE=vb]Dim strFilePath As String

            strFilePath = "D:\imageDogs\C hestertheDog.jp g" 'Absolute File Path

            'File Name with Extension (.jpg)
            strFilePath = Right$(strFileP ath, Len(strFilePath ) - InStrRev(strFil ePath, "\"))strFilePat h = Left$(strFilePa th, Len(strFilePath ) - 4) ' Base File Name
            Debug.Print strFilePath 'see OUTPUT below[/CODE]
            OUTPUT:
            Code:
            ChestertheDog
            Hi ADezii,

            Thanks so much. I'll give this a try. I've been working on the previous one, but I wasn't getting the results I needed. I still need the full paths to be stored, but only view a portion of the string in the control window. Is that what yours does?I can't lose the actual path because my command buttons (previous & next) for search through the images is based on that.

            How would I declare strFilePath since it will change with every end user once I put this out on server? There will be an absolute path, but it won't be hardcoded.

            The control name that will display name is called textdescription . Control is based on the 'imageFile'.... which displays (in subform) the actual image picture and show the absolute path in the current 'textdescriptio n window. That path is stored in db so end-users can search. thanks so much.

            Comment

            • imrosie
              New Member
              • May 2007
              • 222

              #7
              Originally posted by MikeTheBike
              Hi



              Does this help ?

              Code:
              Sub test()
                  Dim Temp As String
                  Dim FName As String
                  Dim Ext As String
                  Temp = "D:\imageDogs\ChestertheDog.jpg"
              
                  Ext = Mid(Temp, InStrRev(Temp, ".") + 1)
              
                  FName = Left(Temp, InStrRev(Temp, ".") - 1)
                  FName = Mid(FName, InStrRev(Temp, "\") + 1)
                  
                  MsgBox "File Name = " & FName
                  MsgBox "Extention = " & Ext
                  
              End Sub
              MTB
              Hi MiketheBike,

              Thanks for your suggestion. Will this give me the name only in the control window, with the full path stored in the db? I have a variable called imageFile (basis of display of the actual image file in subform window and shows full path name in the form control called textdescription ). Is the full path retained in db with your code or do I lose the full path? I only wanted to cut off the unneccessary part of the name in the form. thanks for your help.

              Rosie

              Comment

              • ADezii
                Recognized Expert Expert
                • Apr 2006
                • 8834

                #8
                Originally posted by imrosie
                Hi ADezii,

                Thanks so much. I'll give this a try. I've been working on the previous one, but I wasn't getting the results I needed. I still need the full paths to be stored, but only view a portion of the string in the control window. Is that what yours does?I can't lose the actual path because my command buttons (previous & next) for search through the images is based on that.

                How would I declare strFilePath since it will change with every end user once I put this out on server? There will be an absolute path, but it won't be hardcoded.

                The control name that will display name is called textdescription . Control is based on the 'imageFile'.... which displays (in subform) the actual image picture and show the absolute path in the current 'textdescriptio n window. That path is stored in db so end-users can search. thanks so much.
                Assumptions:
                1. The Bound Field [TextDescription] displays the Absolute Path to the File.
                2. The newly created Field [txtBaseFile] will display the Base Filename only without the .jpg extension.


                Instructions:
                1. Copy and Paste the Function below into your Form's Code Module.
                  [CODE=vb]Private Function fParseFilePath( strFilePath As String) As String

                  'File Name with Extension (.jpg)
                  strFilePath = Right$(strFileP ath, Len(strFilePath ) - InStrRev(strFil ePath, "\"))
                  strFilePath = Left$(strFilePa th, Len(strFilePath ) - 4) ' Base File Name
                  fParseFilePath = strFilePath 'see OUTPUT below
                  End Function[/CODE]
                2. Place this code in your Form's Current() Event.
                  [CODE=vb]Private Sub Form_Current()
                  If IsNull(Me![TextDescription]) Then Exit Sub

                  Me![txtBaseFile] = fParseFilePath( Me![TextDescription])
                  End Sub[/CODE]
                3. For each Record, the Base Filename will now be displayed in the Unboound Text Box Control txtBaseFile.

                Comment

                • imrosie
                  New Member
                  • May 2007
                  • 222

                  #9
                  Originally posted by ADezii
                  Assumptions:
                  1. The Bound Field [TextDescription] displays the Absolute Path to the File.
                  2. The newly created Field [txtBaseFile] will display the Base Filename only without the .jpg extension.


                  Instructions:
                  1. Copy and Paste the Function below into your Form's Code Module.
                    [CODE=vb]Private Function fParseFilePath( strFilePath As String) As String

                    'File Name with Extension (.jpg)
                    strFilePath = Right$(strFileP ath, Len(strFilePath ) - InStrRev(strFil ePath, "\"))
                    strFilePath = Left$(strFilePa th, Len(strFilePath ) - 4) ' Base File Name
                    fParseFilePath = strFilePath 'see OUTPUT below
                    End Function[/CODE]
                  2. Place this code in your Form's Current() Event.
                    [CODE=vb]Private Sub Form_Current()
                    If IsNull(Me![TextDescription]) Then Exit Sub

                    Me![txtBaseFile] = fParseFilePath( Me![TextDescription])
                    End Sub[/CODE]
                  3. For each Record, the Base Filename will now be displayed in the Unboound Text Box Control txtBaseFile.
                  I'm not clear Do you mean on the main form control module?,,, not an event for the actual control? for pasting the funtion. I have two base Modules; 1 for opening the file and 1 for loading the images...I put them in both modules, 1 at a time and I get this error that it doesn't recognize the fParseFilePath( Me![TextDescription]). So I'm not sure where to put it; here are 2 modules:

                  BaseFileOpen: Option Compare Database
                  Option Explicit

                  ' Code to display standard "Open File" dialog.

                  Type OPENFILENAME
                  lStructSize As Long
                  hwndOwner As Long
                  hInstance As Long
                  lpstrFilter As String
                  lpstrCustomFilt er As String
                  nMaxCustFilter As Long
                  nFilterIndex As Long
                  lpstrFile As String
                  nMaxFile As Long
                  lpstrFileTitle As String
                  nMaxFileTitle As Long
                  lpstrInitialDir As String
                  lpstrTitle As String
                  flags As Long
                  nFileOffset As Integer
                  nFileExtension As Integer
                  lpstrDefExt As String
                  lCustData As Long
                  lpfnHook As Long
                  lpTemplateName As String
                  End Type

                  Private Declare Function GetOpenFileName Lib "comdlg32.d ll" Alias _
                  "GetOpenFileNam eA" (OFN As OPENFILENAME) As Boolean

                  Private Declare Function GetSaveFileName Lib "comdlg32.d ll" Alias _
                  "GetSaveFileNam eA" (OFN As OPENFILENAME) As Boolean

                  Private Const ALLFILES = "All files"

                  Function MakeFilterStrin g(ParamArray varFilt() As Variant) As String
                  ' Create filter string.
                  ' Returns "" if there are no arguments.
                  ' Expects an even number of arguments (filter name, extension).
                  ' Adds *.* if the number of arguments is odd.

                  Dim strFilter As String
                  Dim intRes As Integer
                  Dim intNum As Integer

                  intNum = UBound(varFilt)
                  If (intNum <> -1) Then
                  For intRes = 0 To intNum
                  strFilter = strFilter & varFilt(intRes) & vbNullChar
                  Next
                  If intNum Mod 2 = 0 Then
                  strFilter = strFilter & "*.*" & vbNullChar
                  End If

                  strFilter = strFilter & vbNullChar
                  End If

                  MakeFilterStrin g = strFilter
                  End Function

                  Private Sub InitOFN(OFN As OPENFILENAME)
                  With OFN
                  ' Initialize fields user doesn't want to know about
                  .hwndOwner = hWndAccessApp
                  .hInstance = 0
                  .lpstrCustomFil ter = vbNullString
                  .nMaxCustFilter = 0
                  .lpfnHook = 0
                  .lpTemplateName = 0
                  .lCustData = 0
                  .nMaxFile = 511
                  .lpstrFileTitle = String(512, vbNullChar)
                  .nMaxFileTitle = 511
                  .lStructSize = Len(OFN)
                  ' Use default filter if not specified.
                  If .lpstrFilter = "" Then
                  .lpstrFilter = MakeFilterStrin g(ALLFILES)
                  End If
                  ' Pad lpstrFile with null chars.
                  .lpstrFile = .lpstrFile & String(512 - Len(.lpstrFile) , vbNullChar)
                  End With
                  End Sub

                  Function OpenDialog(OFN As OPENFILENAME) As Boolean
                  Dim intRes As Integer
                  InitOFN OFN
                  intRes = GetOpenFileName (OFN)
                  If intRes Then
                  ' Remove trailing null chars from lpstrFile.
                  With OFN
                  .lpstrFile = Left$(.lpstrFil e, InStr(.lpstrFil e, vbNullChar) - 1)
                  End With
                  End If
                  OpenDialog = intRes
                  End Function

                  BaseLoadImage:
                  Option Compare Database
                  Option Explicit

                  Declare Function ShellExecute Lib "shell32.dl l" Alias "ShellExecu teA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

                  Public Function OpenFile(sFileN ame As String)
                  On Error GoTo Err_OpenFile

                  OpenFile = ShellExecute(Ap plication.hWndA ccessApp, "Open", sFileName, "", "C:\", 1)

                  Exit_OpenFile:
                  Exit Function

                  Err_OpenFile:
                  MsgBox Err.Number & " - " & Err.Description
                  Resume Exit_OpenFile

                  End Function

                  Comment

                  • imrosie
                    New Member
                    • May 2007
                    • 222

                    #10
                    Hello and apologies ADezii....

                    I finally got it working as you designed.....th ere is one little issue....when I select a file, it give me an error on some files...."inval id use of a null"....
                    When this happens, it totally breaks the control with the previous file name stuck in there, and I have to close the form and reopen to start again.....How can I fix this? thanks

                    Rosie

                    Comment

                    • ADezii
                      Recognized Expert Expert
                      • Apr 2006
                      • 8834

                      #11
                      Originally posted by imrosie
                      Hello and apologies ADezii....

                      I finally got it working as you designed.....th ere is one little issue....when I select a file, it give me an error on some files...."inval id use of a null"....
                      When this happens, it totally breaks the control with the previous file name stuck in there, and I have to close the form and reopen to start again.....How can I fix this? thanks

                      Rosie
                      Rosie, I need to know exactly where and when this Error is occurring.

                      Comment

                      • imrosie
                        New Member
                        • May 2007
                        • 222

                        #12
                        Originally posted by ADezii
                        Rosie, I need to know exactly where and when this Error is occurring.
                        Hello ADezii,

                        I went back to a backup copy and started all over again inserting your code. What's happening now is the in the 'Form Current' it gives the compile error "Sub or Function" not defined.....So at this point nothing is working.

                        I have 2 base Modules, 1 for the loading of the images and one for opening files (general declarations). I pasted it in the bottom of the 2nd module:

                        Option Compare Database
                        Option Explicit

                        ' Code to display standard "Open File" dialog.

                        Type OPENFILENAME
                        lStructSize As Long
                        hwndOwner As Long
                        hInstance As Long
                        lpstrFilter As String
                        lpstrCustomFilt er As String
                        nMaxCustFilter As Long
                        nFilterIndex As Long
                        lpstrFile As String
                        nMaxFile As Long
                        lpstrFileTitle As String
                        nMaxFileTitle As Long
                        lpstrInitialDir As String
                        lpstrTitle As String
                        flags As Long
                        nFileOffset As Integer
                        nFileExtension As Integer
                        lpstrDefExt As String
                        lCustData As Long
                        lpfnHook As Long
                        lpTemplateName As String
                        End Type

                        Private Declare Function GetOpenFileName Lib "comdlg32.d ll" Alias _
                        "GetOpenFileNam eA" (OFN As OPENFILENAME) As Boolean

                        Private Declare Function GetSaveFileName Lib "comdlg32.d ll" Alias _
                        "GetSaveFileNam eA" (OFN As OPENFILENAME) As Boolean

                        Private Const ALLFILES = "All files"

                        Function MakeFilterStrin g(ParamArray varFilt() As Variant) As String
                        ' Create filter string.
                        ' Returns "" if there are no arguments.
                        ' Expects an even number of arguments (filter name, extension).
                        ' Adds *.* if the number of arguments is odd.

                        Dim strFilter As String
                        Dim intRes As Integer
                        Dim intNum As Integer

                        intNum = UBound(varFilt)
                        If (intNum <> -1) Then
                        For intRes = 0 To intNum
                        strFilter = strFilter & varFilt(intRes) & vbNullChar
                        Next
                        If intNum Mod 2 = 0 Then
                        strFilter = strFilter & "*.*" & vbNullChar
                        End If

                        strFilter = strFilter & vbNullChar
                        End If

                        MakeFilterStrin g = strFilter
                        End Function

                        Private Sub InitOFN(OFN As OPENFILENAME)
                        With OFN
                        ' Initialize fields user doesn't want to know about
                        .hwndOwner = hWndAccessApp
                        .hInstance = 0
                        .lpstrCustomFil ter = vbNullString
                        .nMaxCustFilter = 0
                        .lpfnHook = 0
                        .lpTemplateName = 0
                        .lCustData = 0
                        .nMaxFile = 511
                        .lpstrFileTitle = String(512, vbNullChar)
                        .nMaxFileTitle = 511
                        .lStructSize = Len(OFN)
                        ' Use default filter if not specified.
                        If .lpstrFilter = "" Then
                        .lpstrFilter = MakeFilterStrin g(ALLFILES)
                        End If
                        ' Pad lpstrFile with null chars.
                        .lpstrFile = .lpstrFile & String(512 - Len(.lpstrFile) , vbNullChar)
                        End With
                        End Sub

                        Function OpenDialog(OFN As OPENFILENAME) As Boolean
                        Dim intRes As Integer
                        InitOFN OFN
                        intRes = GetOpenFileName (OFN)
                        If intRes Then
                        ' Remove trailing null chars from lpstrFile.
                        With OFN
                        .lpstrFile = Left$(.lpstrFil e, InStr(.lpstrFil e, vbNullChar) - 1)
                        End With
                        End If
                        OpenDialog = intRes
                        End Function

                        Private Function fParseFilePath( strFilePath As String) As String

                        'File Name with Extension (.jpg or .gif, etc.)
                        strFilePath = Right$(strFileP ath, Len(strFilePath ) - InStrRev(strFil ePath, "\"))
                        strFilePath = Left$(strFilePa th, Len(strFilePath ) - 4) ' Base File Name
                        fParseFilePath = strFilePath
                        End Function

                        Should I have 'Private Declare Functon' for fParse? thanks

                        Comment

                        • imrosie
                          New Member
                          • May 2007
                          • 222

                          #13
                          Originally posted by imrosie
                          Hi MiketheBike,

                          Thanks for your suggestion. Will this give me the name only in the control window, with the full path stored in the db? I have a variable called imageFile (basis of display of the actual image file in subform window and shows full path name in the form control called textdescription ). Is the full path retained in db with your code or do I lose the full path? I only wanted to cut off the unneccessary part of the name in the form. thanks for your help.

                          Rosie
                          Hi Mike, I pasted this into the control.....it does not work..Do you have another suggestion? thanks

                          Rosie

                          Comment

                          • ADezii
                            Recognized Expert Expert
                            • Apr 2006
                            • 8834

                            #14
                            Originally posted by imrosie
                            Hello ADezii,

                            I went back to a backup copy and started all over again inserting your code. What's happening now is the in the 'Form Current' it gives the compile error "Sub or Function" not defined.....So at this point nothing is working.

                            I have 2 base Modules, 1 for the loading of the images and one for opening files (general declarations). I pasted it in the bottom of the 2nd module:

                            Option Compare Database
                            Option Explicit

                            ' Code to display standard "Open File" dialog.

                            Type OPENFILENAME
                            lStructSize As Long
                            hwndOwner As Long
                            hInstance As Long
                            lpstrFilter As String
                            lpstrCustomFilt er As String
                            nMaxCustFilter As Long
                            nFilterIndex As Long
                            lpstrFile As String
                            nMaxFile As Long
                            lpstrFileTitle As String
                            nMaxFileTitle As Long
                            lpstrInitialDir As String
                            lpstrTitle As String
                            flags As Long
                            nFileOffset As Integer
                            nFileExtension As Integer
                            lpstrDefExt As String
                            lCustData As Long
                            lpfnHook As Long
                            lpTemplateName As String
                            End Type

                            Private Declare Function GetOpenFileName Lib "comdlg32.d ll" Alias _
                            "GetOpenFileNam eA" (OFN As OPENFILENAME) As Boolean

                            Private Declare Function GetSaveFileName Lib "comdlg32.d ll" Alias _
                            "GetSaveFileNam eA" (OFN As OPENFILENAME) As Boolean

                            Private Const ALLFILES = "All files"

                            Function MakeFilterStrin g(ParamArray varFilt() As Variant) As String
                            ' Create filter string.
                            ' Returns "" if there are no arguments.
                            ' Expects an even number of arguments (filter name, extension).
                            ' Adds *.* if the number of arguments is odd.

                            Dim strFilter As String
                            Dim intRes As Integer
                            Dim intNum As Integer

                            intNum = UBound(varFilt)
                            If (intNum <> -1) Then
                            For intRes = 0 To intNum
                            strFilter = strFilter & varFilt(intRes) & vbNullChar
                            Next
                            If intNum Mod 2 = 0 Then
                            strFilter = strFilter & "*.*" & vbNullChar
                            End If

                            strFilter = strFilter & vbNullChar
                            End If

                            MakeFilterStrin g = strFilter
                            End Function

                            Private Sub InitOFN(OFN As OPENFILENAME)
                            With OFN
                            ' Initialize fields user doesn't want to know about
                            .hwndOwner = hWndAccessApp
                            .hInstance = 0
                            .lpstrCustomFil ter = vbNullString
                            .nMaxCustFilter = 0
                            .lpfnHook = 0
                            .lpTemplateName = 0
                            .lCustData = 0
                            .nMaxFile = 511
                            .lpstrFileTitle = String(512, vbNullChar)
                            .nMaxFileTitle = 511
                            .lStructSize = Len(OFN)
                            ' Use default filter if not specified.
                            If .lpstrFilter = "" Then
                            .lpstrFilter = MakeFilterStrin g(ALLFILES)
                            End If
                            ' Pad lpstrFile with null chars.
                            .lpstrFile = .lpstrFile & String(512 - Len(.lpstrFile) , vbNullChar)
                            End With
                            End Sub

                            Function OpenDialog(OFN As OPENFILENAME) As Boolean
                            Dim intRes As Integer
                            InitOFN OFN
                            intRes = GetOpenFileName (OFN)
                            If intRes Then
                            ' Remove trailing null chars from lpstrFile.
                            With OFN
                            .lpstrFile = Left$(.lpstrFil e, InStr(.lpstrFil e, vbNullChar) - 1)
                            End With
                            End If
                            OpenDialog = intRes
                            End Function

                            Private Function fParseFilePath( strFilePath As String) As String

                            'File Name with Extension (.jpg or .gif, etc.)
                            strFilePath = Right$(strFileP ath, Len(strFilePath ) - InStrRev(strFil ePath, "\"))
                            strFilePath = Left$(strFilePa th, Len(strFilePath ) - 4) ' Base File Name
                            fParseFilePath = strFilePath
                            End Function

                            Should I have 'Private Declare Functon' for fParse? thanks
                            Rosie, refer to Post 9, Item #1 under the Instructions Heading. If this is somehow causing you problems. copy and paste the Function code into 1 of your 'Base' Modules but preface it with Public as in the code listing below. This Function will now be 'Global' and can be referenced from anywhere within your Application. Let me know how you make out:
                            [CODE=vb]Public Function fParseFilePath( strFilePath As String) As String
                            'File Name with Extension (.jpg)
                            strFilePath = Right$(strFileP ath, Len(strFilePath ) - InStrRev(strFil ePath, "\"))
                            strFilePath = Left$(strFilePa th, Len(strFilePath ) - 4) ' Base File Name
                            fParseFilePath = strFilePath
                            End Function[/CODE]

                            Comment

                            • imrosie
                              New Member
                              • May 2007
                              • 222

                              #15
                              Originally posted by ADezii
                              Rosie, refer to Post 9, Item #1 under the Instructions Heading. If this is somehow causing you problems. copy and paste the Function code into 1 of your 'Base' Modules but preface it with Public as in the code listing below. This Function will now be 'Global' and can be referenced from anywhere within your Application. Let me know how you make out:
                              [CODE=vb]Public Function fParseFilePath( strFilePath As String) As String
                              'File Name with Extension (.jpg)
                              strFilePath = Right$(strFileP ath, Len(strFilePath ) - InStrRev(strFil ePath, "\"))
                              strFilePath = Left$(strFilePa th, Len(strFilePath ) - 4) ' Base File Name
                              fParseFilePath = strFilePath
                              End Function[/CODE]
                              Thanks so much for this.....I'm goihg to try this out now..I'll get back to you with the results....

                              Rosie

                              Comment

                              Working...