Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2006

Tip: Looking for answers? Try searching our database.

Pull characters from a file name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
obiwaugh - 13 Sep 2006 23:00 GMT
Let's say that I have a file with path C:\TEMP\LRQAD362.CHK

The 3 numbers are significant to the purpose of the file...how do I get those
3 numbers out, and use them in as a string?

Thanks in advance!
Douglas J. Steele - 13 Sep 2006 23:13 GMT
Always 3 digits in front of the file extension? Try:

Mid(strFilePath, InStrRev(strFilePath, ".") - 3, 3)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Let's say that I have a file with path C:\TEMP\LRQAD362.CHK
>
[quoted text clipped - 3 lines]
>
> Thanks in advance!
obiwaugh - 13 Sep 2006 23:32 GMT
Alright...I don't think my original question was complete.  In the code you
supplied, it appears that I would need to enter the full path.

In my scenario, I will need the code to look in the specific folder and pull
the 3 numbers from the file name.  Yes, it's always the 3 digits before the
extension.

>Always 3 digits in front of the file extension? Try:
>
[quoted text clipped - 5 lines]
>>
>> Thanks in advance!
Douglas J. Steele - 14 Sep 2006 00:31 GMT
Dim intNumber As Integer
Dim strPath As String
Dim strFile As String

  strPath = "C:\Temp\"
  strFile = Dir(strPath & "*.CHK)
  If Len(strFile) > 0 Then
     intNumber = Mid(strFilePath, InStrRev(strFile, ".") - 3, 3)
  End If

That's assuming there's only one .CHK file you interested in in that folder.
If there are multiple, use:

Dim intNumber As Integer
Dim strPath As String
Dim strFile As String

  strPath = "C:\Temp\"
  strFile = Dir(strPath & "*.CHK)
  Do While Len(strFile) > 0
     intNumber = Mid(strFilePath, InStrRev(strFile, ".") - 3, 3)
     strFile = Dir()
  Loop

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Alright...I don't think my original question was complete.  In the code
> you
[quoted text clipped - 15 lines]
>>>
>>> Thanks in advance!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.