473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

InStr and StrReverse

imrosie
222 100+
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\ChestertheDog.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
Jun 7 '07 #1
20 4904
FishVal
2,653 Expert 2GB
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\ChestertheDog.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 "FileFullPath". Hereby I attach the code.

Class module "FileFullPath":

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim strFilePath As String, strFileName As String, strFileExt As String
  3.  
  4. Public Property Get Path() As String
  5.     Path = strFilePath
  6. End Property
  7.  
  8. Public Property Let Path(ByVal strNewValue As String)
  9.     strFilePath = strNewValue
  10. End Property
  11.  
  12. Public Property Get FileName() As String
  13.     FileName = strFileName
  14. End Property
  15.  
  16. Public Property Let FileName(ByVal strNewValue As String)
  17.     strFileName = strNewValue
  18. End Property
  19.  
  20. Public Property Get Extension() As String
  21.     Extension = strFileExt
  22. End Property
  23.  
  24. Public Property Let Extension(ByVal strNewValue As String)
  25.     strFileExt = strNewValue
  26. End Property
  27.  
  28. Public Property Get FullName() As String
  29.  
  30.     With Me
  31.         FullName = .Path & "\" & .FileName & "." & .Extension
  32.     End With
  33.  
  34. End Property
  35.  
  36. Public Property Let FullName(ByVal strNewValue As String)
  37.  
  38.     With Me
  39.         .Path = CutSubString(strNewValue, "\")
  40.         .FileName = CutSubString(strNewValue, ".")
  41.         .Extension = strNewValue
  42.     End With
  43.  
  44. End Property
  45.  
  46. Private Function CutSubString(ByRef strInput As String, _
  47.                               ByVal strTerminator As String) As String
  48.  
  49.     Dim intNewPos As Integer, intPos As Integer
  50.  
  51.     intNewPos = 0
  52.     Do
  53.         intPos = intNewPos
  54.         intNewPos = InStr(intPos + 1, strInput, strTerminator, vbTextCompare)
  55.     Loop Until intNewPos = 0
  56.     CutSubString = Left(strInput, intPos - 1)
  57.     strInput = Right(strInput, Len(strInput) - intPos)
  58.  
  59. End Function
  60.  
  61.  
Form module:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub FileLink_AfterUpdate()
  3.  
  4.     Dim objFileLink As New FileFullPath
  5.  
  6.     With objFileLink
  7.         .FullName = Me![FileLink]
  8.         Me![Path] = .Path
  9.         Me![Name] = .FileName
  10.         Me![Extension] = .Extension
  11.     End With
  12.  
  13.     Set objFileLink = Nothing
  14.  
  15. End Sub
  16.  
  17.  
Jun 7 '07 #2
imrosie
222 100+
Hi!

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

Class module "FileFullPath":

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim strFilePath As String, strFileName As String, strFileExt As String
  3.  
  4. Public Property Get Path() As String
  5.     Path = strFilePath
  6. End Property
  7.  
  8. Public Property Let Path(ByVal strNewValue As String)
  9.     strFilePath = strNewValue
  10. End Property
  11.  
  12. Public Property Get FileName() As String
  13.     FileName = strFileName
  14. End Property
  15.  
  16. Public Property Let FileName(ByVal strNewValue As String)
  17.     strFileName = strNewValue
  18. End Property
  19.  
  20. Public Property Get Extension() As String
  21.     Extension = strFileExt
  22. End Property
  23.  
  24. Public Property Let Extension(ByVal strNewValue As String)
  25.     strFileExt = strNewValue
  26. End Property
  27.  
  28. Public Property Get FullName() As String
  29.  
  30.     With Me
  31.         FullName = .Path & "\" & .FileName & "." & .Extension
  32.     End With
  33.  
  34. End Property
  35.  
  36. Public Property Let FullName(ByVal strNewValue As String)
  37.  
  38.     With Me
  39.         .Path = CutSubString(strNewValue, "\")
  40.         .FileName = CutSubString(strNewValue, ".")
  41.         .Extension = strNewValue
  42.     End With
  43.  
  44. End Property
  45.  
  46. Private Function CutSubString(ByRef strInput As String, _
  47.                               ByVal strTerminator As String) As String
  48.  
  49.     Dim intNewPos As Integer, intPos As Integer
  50.  
  51.     intNewPos = 0
  52.     Do
  53.         intPos = intNewPos
  54.         intNewPos = InStr(intPos + 1, strInput, strTerminator, vbTextCompare)
  55.     Loop Until intNewPos = 0
  56.     CutSubString = Left(strInput, intPos - 1)
  57.     strInput = Right(strInput, Len(strInput) - intPos)
  58.  
  59. End Function
  60.  
  61.  
Form module:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub FileLink_AfterUpdate()
  3.  
  4.     Dim objFileLink As New FileFullPath
  5.  
  6.     With objFileLink
  7.         .FullName = Me![FileLink]
  8.         Me![Path] = .Path
  9.         Me![Name] = .FileName
  10.         Me![Extension] = .Extension
  11.     End With
  12.  
  13.     Set objFileLink = Nothing
  14.  
  15. End Sub
  16.  
  17.  

All I can say is WOW! FishVal.....Iread 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
Jun 7 '07 #3
ADezii
8,834 Expert 8TB
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\ChestertheDog.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:
Expand|Select|Wrap|Line Numbers
  1. Dim strFilePath As String
  2.  
  3. strFilePath = "D:\imageDogs\ChestertheDog.jpg"        'Absolute File Path
  4.  
  5. 'File Name with Extension (.jpg)
  6. strFilePath = Right$(strFilePath, Len(strFilePath) - InStrRev(strFilePath, "\"))strFilePath = Left$(strFilePath, Len(strFilePath) - 4)    ' Base File Name
  7.    Debug.Print strFilePath     'see OUTPUT below
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. ChestertheDog
Jun 8 '07 #4
MikeTheBike
639 Expert 512MB
Hi

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\ChestertheDog.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 ?

Expand|Select|Wrap|Line Numbers
  1. Sub test()
  2.     Dim Temp As String
  3.     Dim FName As String
  4.     Dim Ext As String
  5.     Temp = "D:\imageDogs\ChestertheDog.jpg"
  6.  
  7.     Ext = Mid(Temp, InStrRev(Temp, ".") + 1)
  8.  
  9.     FName = Left(Temp, InStrRev(Temp, ".") - 1)
  10.     FName = Mid(FName, InStrRev(Temp, "\") + 1)
  11.  
  12.     MsgBox "File Name = " & FName
  13.     MsgBox "Extention = " & Ext
  14.  
  15. End Sub
  16.  
MTB
Jun 8 '07 #5
imrosie
222 100+
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:
Expand|Select|Wrap|Line Numbers
  1. Dim strFilePath As String
  2.  
  3. strFilePath = "D:\imageDogs\ChestertheDog.jpg"        'Absolute File Path
  4.  
  5. 'File Name with Extension (.jpg)
  6. strFilePath = Right$(strFilePath, Len(strFilePath) - InStrRev(strFilePath, "\"))strFilePath = Left$(strFilePath, Len(strFilePath) - 4)    ' Base File Name
  7.    Debug.Print strFilePath     'see OUTPUT below
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. 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 'textdescription window. That path is stored in db so end-users can search. thanks so much.
Jun 8 '07 #6
imrosie
222 100+
Hi



Does this help ?

Expand|Select|Wrap|Line Numbers
  1. Sub test()
  2.     Dim Temp As String
  3.     Dim FName As String
  4.     Dim Ext As String
  5.     Temp = "D:\imageDogs\ChestertheDog.jpg"
  6.  
  7.     Ext = Mid(Temp, InStrRev(Temp, ".") + 1)
  8.  
  9.     FName = Left(Temp, InStrRev(Temp, ".") - 1)
  10.     FName = Mid(FName, InStrRev(Temp, "\") + 1)
  11.  
  12.     MsgBox "File Name = " & FName
  13.     MsgBox "Extention = " & Ext
  14.  
  15. End Sub
  16.  
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
Jun 8 '07 #7
ADezii
8,834 Expert 8TB
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 'textdescription 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.
    Expand|Select|Wrap|Line Numbers
    1. Private Function fParseFilePath(strFilePath As String) As String
    2.  
    3. 'File Name with Extension (.jpg)
    4. strFilePath = Right$(strFilePath, Len(strFilePath) - InStrRev(strFilePath, "\"))
    5. strFilePath = Left$(strFilePath, Len(strFilePath) - 4)    ' Base File Name
    6.    fParseFilePath = strFilePath     'see OUTPUT below
    7. End Function
  2. Place this code in your Form's Current() Event.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Current()
    2.   If IsNull(Me![TextDescription]) Then Exit Sub
    3.  
    4.   Me![txtBaseFile] = fParseFilePath(Me![TextDescription])
    5. End Sub
  3. For each Record, the Base Filename will now be displayed in the Unboound Text Box Control txtBaseFile.
Jun 8 '07 #8
imrosie
222 100+
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.
    Expand|Select|Wrap|Line Numbers
    1. Private Function fParseFilePath(strFilePath As String) As String
    2.  
    3. 'File Name with Extension (.jpg)
    4. strFilePath = Right$(strFilePath, Len(strFilePath) - InStrRev(strFilePath, "\"))
    5. strFilePath = Left$(strFilePath, Len(strFilePath) - 4)    ' Base File Name
    6.    fParseFilePath = strFilePath     'see OUTPUT below
    7. End Function
  2. Place this code in your Form's Current() Event.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Current()
    2.   If IsNull(Me![TextDescription]) Then Exit Sub
    3.  
    4.   Me![txtBaseFile] = fParseFilePath(Me![TextDescription])
    5. End Sub
  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
lpstrCustomFilter 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.dll" Alias _
"GetOpenFileNameA" (OFN As OPENFILENAME) As Boolean

Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
"GetSaveFileNameA" (OFN As OPENFILENAME) As Boolean

Private Const ALLFILES = "All files"

Function MakeFilterString(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

MakeFilterString = strFilter
End Function

Private Sub InitOFN(OFN As OPENFILENAME)
With OFN
' Initialize fields user doesn't want to know about
.hwndOwner = hWndAccessApp
.hInstance = 0
.lpstrCustomFilter = 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 = MakeFilterString(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$(.lpstrFile, InStr(.lpstrFile, vbNullChar) - 1)
End With
End If
OpenDialog = intRes
End Function

BaseLoadImage:
Option Compare Database
Option Explicit

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (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(sFileName As String)
On Error GoTo Err_OpenFile

OpenFile = ShellExecute(Application.hWndAccessApp, "Open", sFileName, "", "C:\", 1)

Exit_OpenFile:
Exit Function

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

End Function
Jun 8 '07 #9
imrosie
222 100+
Hello and apologies ADezii....

I finally got it working as you designed.....there is one little issue....when I select a file, it give me an error on some files...."invalid 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
Jun 8 '07 #10
ADezii
8,834 Expert 8TB
Hello and apologies ADezii....

I finally got it working as you designed.....there is one little issue....when I select a file, it give me an error on some files...."invalid 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.
Jun 8 '07 #11
imrosie
222 100+
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
lpstrCustomFilter 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.dll" Alias _
"GetOpenFileNameA" (OFN As OPENFILENAME) As Boolean

Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
"GetSaveFileNameA" (OFN As OPENFILENAME) As Boolean

Private Const ALLFILES = "All files"

Function MakeFilterString(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

MakeFilterString = strFilter
End Function

Private Sub InitOFN(OFN As OPENFILENAME)
With OFN
' Initialize fields user doesn't want to know about
.hwndOwner = hWndAccessApp
.hInstance = 0
.lpstrCustomFilter = 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 = MakeFilterString(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$(.lpstrFile, InStr(.lpstrFile, 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$(strFilePath, Len(strFilePath) - InStrRev(strFilePath, "\"))
strFilePath = Left$(strFilePath, Len(strFilePath) - 4) ' Base File Name
fParseFilePath = strFilePath
End Function

Should I have 'Private Declare Functon' for fParse? thanks
Jun 9 '07 #12
imrosie
222 100+
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
Jun 14 '07 #13
ADezii
8,834 Expert 8TB
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
lpstrCustomFilter 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.dll" Alias _
"GetOpenFileNameA" (OFN As OPENFILENAME) As Boolean

Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
"GetSaveFileNameA" (OFN As OPENFILENAME) As Boolean

Private Const ALLFILES = "All files"

Function MakeFilterString(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

MakeFilterString = strFilter
End Function

Private Sub InitOFN(OFN As OPENFILENAME)
With OFN
' Initialize fields user doesn't want to know about
.hwndOwner = hWndAccessApp
.hInstance = 0
.lpstrCustomFilter = 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 = MakeFilterString(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$(.lpstrFile, InStr(.lpstrFile, 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$(strFilePath, Len(strFilePath) - InStrRev(strFilePath, "\"))
strFilePath = Left$(strFilePath, 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:
Expand|Select|Wrap|Line Numbers
  1. Public Function fParseFilePath(strFilePath As String) As String
  2.   'File Name with Extension (.jpg)
  3.   strFilePath = Right$(strFilePath, Len(strFilePath) - InStrRev(strFilePath, "\"))
  4.   strFilePath = Left$(strFilePath, Len(strFilePath) - 4)    ' Base File Name
  5.     fParseFilePath = strFilePath    
  6. End Function
Jun 14 '07 #14
imrosie
222 100+
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:
Expand|Select|Wrap|Line Numbers
  1. Public Function fParseFilePath(strFilePath As String) As String
  2.   'File Name with Extension (.jpg)
  3.   strFilePath = Right$(strFilePath, Len(strFilePath) - InStrRev(strFilePath, "\"))
  4.   strFilePath = Left$(strFilePath, Len(strFilePath) - 4)    ' Base File Name
  5.     fParseFilePath = strFilePath    
  6. End Function
Thanks so much for this.....I'm goihg to try this out now..I'll get back to you with the results....

Rosie
Jun 15 '07 #15
ADezii
8,834 Expert 8TB
Thanks so much for this.....I'm goihg to try this out now..I'll get back to you with the results....

Rosie
Keep me posted, Rosie.
Jun 15 '07 #16
imrosie
222 100+
Keep me posted, Rosie.
Hello ADezii,

IT works, I must have put it in the wrong module before, or maybe now that it's global that fixed it, but it does work! Major hurdle to overcome, if you can imagine.
One slight problem, when I browse and select a new image, the last image name is still in 'txtBaseFile', until I save the new image, then move to 'previous', then forward to see the right name associated with the new image. Should I move code from the Form Current event to clear this up? I'll try another event while waiting for your response.

thanks for your major help...

Rosie
Jun 15 '07 #17
ADezii
8,834 Expert 8TB
Hello ADezii,

IT works, I must have put it in the wrong module before, or maybe now that it's global that fixed it, but it does work! Major hurdle to overcome, if you can imagine.
One slight problem, when I browse and select a new image, the last image name is still in 'txtBaseFile', until I save the new image, then move to 'previous', then forward to see the right name associated with the new image. Should I move code from the Form Current event to clear this up? I'll try another event while waiting for your response.

thanks for your major help...

Rosie
Did you follow the code in Post #8, Item #2 under Instructions?
Jun 15 '07 #18
imrosie
222 100+
Did you follow the code in Post #8, Item #2 under Instructions?
Yes ADezii, to the letter. However, I have an event that complains when I recompiled after adding your code. It's the event (using the recordset) matches the imageID to the image. I get a gray bar over the 'Str' in the rs.FindFirst line. I
am too much of a newbie to know how exactly to fix this one.

Private Sub Combo48_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[imageID] = " & Str(Me![Combo48])
Me.Bookmark = rs.Bookmark
End Sub

Here's my 'Private Sub Form_Current code as you directed (your code is bolded):

Private Sub Form_Current()
On Error GoTo HandleErr

Me.RecordsetClone.MoveLast

If (Me.RecordsetClone.RecordCount) < 1.5 Then
Me.cmdNext.Enabled = False
Me.cmdPrev.Enabled = False

ElseIf Me.RecordsetClone.RecordCount = Me.CurrentRecord Then
Me.cmdNext.Enabled = False
Me.cmdPrev.Enabled = True

ElseIf Me.CurrentRecord = 1 Then
Me.cmdNext.Enabled = True
Me.cmdPrev.Enabled = False

Else
Me.cmdNext.Enabled = True
Me.cmdPrev.Enabled = True

End If

If Not IsNull([imageFile]) Then
Forms!frmimageInventory!frmimagesubform![imgPicture].Picture = [imageFile]
SysCmd acSysCmdSetStatus, "Image: '" & [imageFile] & "'."
Else
Forms!frmimageInventory!frmimagesubform![imgPicture].Picture = ""
SysCmd acSysCmdClearStatus
End If
If IsNull(Me![txtDescription]) Then Exit Sub

Me![txtBaseFile] = fParseFilePath(Me![txtDescription])

Exit Sub
HandleErr:
If Err = 2220 Then
Forms!frmimageInventory!frmimagesubform![imgPicture].Picture = ""
SysCmd acSysCmdSetStatus, "Can't open image: '" & [imageFile] & "'"
Else
MsgBox Err.Description, vbExclamation
End If
End Sub

I'm also getting an error regarding this 'Add-in'....I don't know where it's coming from [4tdocm10] . Have you seen this before???
Thanks
Rosie
Jun 17 '07 #19
ADezii
8,834 Expert 8TB
Yes ADezii, to the letter. However, I have an event that complains when I recompiled after adding your code. It's the event (using the recordset) matches the imageID to the image. I get a gray bar over the 'Str' in the rs.FindFirst line. I
am too much of a newbie to know how exactly to fix this one.

Private Sub Combo48_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[imageID] = " & Str(Me![Combo48])
Me.Bookmark = rs.Bookmark
End Sub

Here's my 'Private Sub Form_Current code as you directed (your code is bolded):

Private Sub Form_Current()
On Error GoTo HandleErr

Me.RecordsetClone.MoveLast

If (Me.RecordsetClone.RecordCount) < 1.5 Then
Me.cmdNext.Enabled = False
Me.cmdPrev.Enabled = False

ElseIf Me.RecordsetClone.RecordCount = Me.CurrentRecord Then
Me.cmdNext.Enabled = False
Me.cmdPrev.Enabled = True

ElseIf Me.CurrentRecord = 1 Then
Me.cmdNext.Enabled = True
Me.cmdPrev.Enabled = False

Else
Me.cmdNext.Enabled = True
Me.cmdPrev.Enabled = True

End If

If Not IsNull([imageFile]) Then
Forms!frmimageInventory!frmimagesubform![imgPicture].Picture = [imageFile]
SysCmd acSysCmdSetStatus, "Image: '" & [imageFile] & "'."
Else
Forms!frmimageInventory!frmimagesubform![imgPicture].Picture = ""
SysCmd acSysCmdClearStatus
End If
If IsNull(Me![txtDescription]) Then Exit Sub

Me![txtBaseFile] = fParseFilePath(Me![txtDescription])

Exit Sub
HandleErr:
If Err = 2220 Then
Forms!frmimageInventory!frmimagesubform![imgPicture].Picture = ""
SysCmd acSysCmdSetStatus, "Can't open image: '" & [imageFile] & "'"
Else
MsgBox Err.Description, vbExclamation
End If
End Sub

I'm also getting an error regarding this 'Add-in'....I don't know where it's coming from [4tdocm10] . Have you seen this before???
Thanks
Rosie
Expand|Select|Wrap|Line Numbers
  1. If [ImageID] is a Numeric Field, then this line of code should read:
  2. rs.FindFirst "[imageID] = " & Me![Combo48]
  3.  
  4. If [ImageID] is a String Field, then this line of code should read:
  5. rs.FindFirst "[imageID] = '" & Me![Combo48] & "'"
Jun 17 '07 #20
imrosie
222 100+
Expand|Select|Wrap|Line Numbers
  1. If [ImageID] is a Numeric Field, then this line of code should read:
  2. rs.FindFirst "[imageID] = " & Me![Combo48]
  3.  
  4. If [ImageID] is a String Field, then this line of code should read:
  5. rs.FindFirst "[imageID] = '" & Me![Combo48] & "'"
Thanks ADezii,

I added your code and changed a couple things, now this works great. Thanks so much

Rosie
Jun 18 '07 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: DTB | last post by:
I am trying to convert a complex function from Oracle to SQL Server and have come across Oracle's Instr() function. I see SQL Server has CHARINDEX() which is similar, however it does not provide...
22
by: John Cobb | last post by:
I've removed the Microsoft.VisualBasic import from my VB.Net project and am in the process of replacing the vb6 compatible calls with native .Net i.e. system.datetime.now instead of Now, variable...
6
by: Chris Calzaretta | last post by:
Hello Everybody, Question instr function will give you the first instance of the finding so EX: so your string looks like string1 = "testing>This is > just a test > testtesttest"...
4
by: Gordon | last post by:
Hi; I am trying to extract a substring using a combination of the mid() and Instr() i.e. aString = "Jones, Thomas R, Dr." hold = InStr(1, aString, " ," , 1) newString = Mid(aString, 1,...
4
by: fischerspooner | last post by:
Hi, I'm banging my head against the desk because I can't find a solution for the following simple problem. Case: There is a column in a table that has FamilyName and FirstName(s) in one field....
12
by: rodchar | last post by:
hey all, i'm getting a result that i don't understand i have a string "test1, test2" If InStr("test1") and InStr("test2") Then 'Inside EndIf The inside is not running for some reason. Any...
3
by: lstrudeman | last post by:
Hello; A friend gave me this syntax and they are unavailable at the moment and I need this asap. I am trying to figure out how SQL figures this out. Below the syntax takes a field in a file and...
7
imrosie
by: imrosie | last post by:
Hello, I don't completely understand the working of these functions, but it's been suggested that these will give me what I need. I have a database that pulls in image files (stores the...
3
by: Alex Pavluck | last post by:
I have a date stored like this '2004 - 2006' and I use this code to get startyear and stopyear StartYear: Trim(Left(,InStr(,"-")-1)) StopYear: Trim(Right(,InStr(,"-")-1)) Is there a way to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.