Left Function

  • Thread starter Thread starter a
  • Start date Start date
A

a

thank you



I have text box in my form

this text box contain a value = myfile.txt



explain:

myfile is any size of character after myfile name you will find the
extension

How can I use this function (trim or lift) or any function to remove the
extension of myfile

for above example (.txt)
 
Sorry, are you saying that you want .txt, or that you want myfile?

To get myfile, you'd use

Left(Me!MyTextbox, InStrRev(Me!MyTextbox, ".") - 1)

To get txt, you'd use

Mid(Me!MyTextbox, InStrRev(Me!MyTextbox, ".") + 1)

Of course, there's always a chance that the text box may be empty, or that
what's in it might not have an extension. To be complete, you'd want
something like:

Dim lngPosition As Long
Dim strFileName As String
Dim strExtension As String

lngPosition = InStrRev(Me!MyTextbox & vbNullString, ".")
If lngPosition > 0 Then
strFileName = Left$(Me!MyTextbox, lngPosition - 1)
strExtension = Mid$(Me!MyTextbox, lngPosition + 1)
Else
strFileName = Me!MyTextbox
strExtension = vbNullString
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top