File Names

Brutal

Cannis
Local time
Today, 10:17
Joined
May 7, 2002
Messages
25
I have part numbers in my database and if there are photographs in the image directory with the same number then a photograph is displayed ie P/N abc123 = abc123.jpg. This I have set up and works great - HOWEVER - if the part number in the database is abc/123 the filename cannot contain "/" so they are numbered abc_123.jpg, how can I get this to work??
Any ideas greatfully recieved.


Paul
 
Try the REPLACE function (from Help)
Replace(expression, find, replace[, start[, count[, compare]]])

Check VBA help to see how to use this, but it is used to replace a substring within a string with another value.
 
I can't find the replace function in A97 so built my own...


Code:
Private Sub Command0_Click()
MsgBox strPictureName [COLOR=green]'returns picture name[/color]
End Sub

Private Function strPictureName() As String

Dim tmpStr As String [COLOR=green]'builds string where / exists[/color]
Dim sChar As String [COLOR=green]'holds character to add [/color]
Dim counter As Byte [COLOR=green]'std counter[/color]

If InStr(1, Me.YourField, "/") <> 0 Then [COLOR=green]'only loop if a / is in the field [/color]
    For counter = 1 To Len(Me.YourField)
        If Mid(Me.YourField, counter, 1) = "/" Then [COLOR=green]'is it a slash? [/color]
        sChar = "_" [COLOR=green]'if so replace with underscore[/color]
        Else
        sChar = Mid(Me.YourField, counter, 1) [COLOR=green]'use the character that's there [/color]
        End If
        tmpStr = tmpStr & sChar [COLOR=green]'build it[/color]
    Next counter [COLOR=green]'next char[/color]
    strPictureName = tmpStr & ".jpg" [COLOR=green]'pass result[/color]
Else
    strPictureName = Me.YourField & ".jpg"[COLOR=green]'pass result[/color]
End If

End Function
 
Thanks Both of you
It is time to go for the weekend here, so I will try your suggestions/fixes 1st thing Monday

Thanks again

Paul
 
THANKYOU

Guys you are terrific
I have got it working just fine
Thankyou both again for you help

Paul
 

Users who are viewing this thread

Back
Top Bottom