opening text files

M

ms shakeel

hello

thanks in advance for help

i have a following assignment

Mypath = "c:\windows\desktop\hello.txt"

i want to extract the following details such that
variable1 = c:\windows\desktop\
and variable2 = hello

and by using these variables variable1 and variable2,
i open the text file with name given by variable2 placed
at the path given by variable1
this has to be done by using the shell command as shown
below


thank you
shakeel
(e-mail address removed)
 
D

Dirk Goldgar

ms shakeel said:
hello

thanks in advance for help

i have a following assignment

Mypath = "c:\windows\desktop\hello.txt"

i want to extract the following details such that
variable1 = c:\windows\desktop\
and variable2 = hello

and by using these variables variable1 and variable2,
i open the text file with name given by variable2 placed
at the path given by variable1
this has to be done by using the shell command as shown
below

I don't see anything "shown below", but ...

If "c:\windows\desktop\hello.txt" is an existing file, you can split it
by using the Dir() function to return just the filename itself:

Dim strMyPath As String
Dim strFileName As String
Dim intPos As Integer

strMypath = "c:\windows\desktop\hello.txt"

' Split into path (in strMyPath) and filename (in strFileName)
strFileName = Dir(strMyPath)
If Len(strFileName) > 0 Then
strMyPath = Left$(strMyPath, Len(strMyPath) - Len(strFileName))
End If

' Remove extension from strFileName.
' Note: InStrRev() is not available before Access 2000.
intPos = InStrRev(strFileName, ".")
If intPos > 0 Then
strFileName = Left(strFileName, intPos - 1)
End If

You can reassemble the fully qualified file path from variables like
this:

Dim strFullPath As String

strFullPath = strMyPath & strFileName & ".txt"

However, it's not clear to me what you mean by "opening" the file in
this context. Do you want to open it for processing by Access, or open
it with the registered application, or open it with a specific
application, or what?
 

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

Top