Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a file with Notepad from within Access

Status
Not open for further replies.

InkyRich

Technical User
Aug 2, 2006
126
GB
Hello,
I have to try to open an external file in Notepad from a button click in an Access form.
What code do I need to do that?

InkyRich

A fool and his money are soon parted - so you might as well send it to me!
 
Check Visual Basic Help in Access for the Shell Function
 
using Open Notepad in the Search I found. thread705-1311070
 
Hi bubba,
Thanks that was very useful, and it worked. Do you know how I can insert the variable 'dbPath' into the string for the path to the file?

Private Sub cmdTextpad_Click()
RetVal = Shell("Notepad.EXE [dbPath] FILENAME", 1)
AppActivate RetVal

End Sub

Inky

A fool and his money are soon parted - so you might as well send it to me!
 
something like this ?
RetVal = Shell("Notepad.EXE " & dbPath & "\" & FILENAME", 1)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi phv,
I have tried the line of code.
It doesnt like me typing it in as you show it:
RetVal = Shell("Notepad.EXE " & dbPath & "\" & FILENAME", 1)

so I tried the speech marks before the word FILENAME and it says file not found.

Can you see where I am going wrong?
Incidently the dbPath variable includes the Application name, is this wrong?
If it is how can I delete the application name from the path?

Inky

A fool and his money are soon parted - so you might as well send it to me!
 
Sorry for the typo.
What is the value of dbPath ?
What is FILENAME ?
What is the full pathname of the file you want to open with notepad ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hello phv,
I have managed to get a step nearer in that dbPath gives me the string that I need without the Application name. I now have to attach the Notepad file to the string, but it is tripping out on the Retval, coming up with File Not Found!

This is the complete code:
Code:
Private Sub CmdViewLogfile_Click()
    Dim dbName As String
    Dim dbPath As String
    dbName = Me.Application.CurrentDb.Name
        

dbPath = Left(dbName, InStrRev(dbName, "\"))
  
  
Retval = Shell("Notepad.exe" & dbPath & "TextFileName", 1)

 AppActivate Retval
    
    
 End Sub

Do I need to append '.txt' to the notepad file name?
Many thanks for your help.
Inky

A fool and his money are soon parted - so you might as well send it to me!
 
You will need a space:

"Notepad.exe[COLOR=red yellow] [/color]"

CurrentProject.Path will return the path without a \
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top