Solved

How to Use OLE To invoke notepad application with a particular text file!

Posted on 1998-11-23
1
785 Views
Last Modified: 2010-10-05
Currently for my application, I am printing the output in a text file.  My intention is when the user clicks on the print command button, it should open up Notepad with that particular text file.  I tried the shell function, but that only opens up notepad.  How do I open that particular text file.  I suppose I have to do this with OLE.  If anybody can help me out with this, I would really appreciate it.
Thanks
0
Comment
Question by:vasant
1 Comment
 
LVL 1

Accepted Solution

by:
Jason_G earned 50 total points
ID: 1446442
Hi Vasant,
You can use the following code to do this, just paste it into the code section of your form;

***Start Of Code***
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
       (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
       ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd _
       As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Const SW_SHOWNORMAL = 1
 

     'Description:How do I launch a file in its associated program?

Function StartDoc(DocName As String) As Long

       Dim Scr_hDC As Long
       Scr_hDC = GetDesktopWindow()
       StartDoc = ShellExecute(Scr_hDC, "Open", DocName, "", "C:\", SW_SHOWNORMAL)
End Function
 
Private Sub Form_Click()
       Dim r As Long
       r = StartDoc("c:\your_text_file.txt")
       Debug.Print "Return code from Startdoc: "; r
End Sub
***End Of Code***

I hope this helps!

Sincerely,
Jason

Jason Gorman (jason_gorman@scholars.com)
Learning Advisor, http://scholars.com
Microsoft Certified Technical Education Center
Novell Authorized Online Training Provider
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 51
How to Add / Edit Windows Menu 4 52
TT Auto Dashboard 13 84
MS Access 03, TransferText, decimal places 8 45
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now