Look within text string for a value

Rusty

Registered User.
Local time
Today, 13:08
Joined
Apr 15, 2004
Messages
207
Hey Guys,

I've got a field called [WordLink] on a form where the user enters the file name of the Word or Excel document asociated with the record.

I have a button that opens Word or Excel and then opens the file...not a problem there as I'm using the Call Shell("""C:\Program Files\ command and that works just fine.

However, I need the button to look to see if it's got ".doc" or ".xls" within the text string in the field so it knows whether to open Word or Excel.

I've tried something basic to launch something like a msgbox (see code below) but obviously it doesn't work. How do I look within a text string for a value?

Cheers,

Russ
:D


Code:
If Me.WordLink_filename.Value = "*.doc" Then
MsgBox "This is a word file."
Else
End If
 
Dim strFileName as String
strFileName = Me.Wordlink_filename
If Instr(1, strFileName,".doc") > 0 Then
...put whatever code you want for a Word file here
ElseIf Instr(1, strFileName, ".xls") > 0 Then
...put whatever code you want for an Excel file here
Else
Msgbox "The file is not a Word or Excel Document", vbInformation, "Error"
End If
 
Cheers Bob - that works a treat!! :D

Rusty
:D
 

Users who are viewing this thread

Back
Top Bottom