Solved

Open Notepad from listbox

Posted on 2002-03-20
18
378 Views
Last Modified: 2012-06-27
I have a list box and the 3rd column is file name, how do i make open file with Notepad when clicking on selected item.
0
Comment
Question by:jasonkk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
  • +2
18 Comments
 
LVL 6

Expert Comment

by:xSinbad
ID: 6884038
You should use the shell command;

dim strShell
bknouse ="notepad.exe " & listboxnamehere
call shell (bknouse)
0
 
LVL 6

Expert Comment

by:xSinbad
ID: 6884042
That should be

dim strShell
strShell ="notepad.exe " & listboxnamehere
call shell (bknouse)
0
 
LVL 54

Expert Comment

by:nico5038
ID: 6884049
Check out the SHELL command from the help file. It has a sample like:
Shell("C:\WINDOWS\CALC.EXE", 1)

Nic;o)
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 44

Expert Comment

by:bruintje
ID: 6884064
Private Sub Listbox1_DblClick(Cancel As Integer)
  Shell("C:\WINDOWS\NOTEPAD.EXE" & Listbox1.ItemData(Listbox1.ListIndex), 1)
End Sub

HTH:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6884072
Private Sub Listbox1_DblClick(Cancel As Integer)
 Shell "C:\WINDOWS\NOTEPAD.EXE" & Listbox1.ItemData(Listbox1.ListIndex), 1
End Sub

0
 

Author Comment

by:jasonkk
ID: 6884083
xSinbad,

The listbox has 3 columns and sometimes the record is more than 1.
I need to know how to open file with Notepad when clicking on selected item based on 3rd column data from multiple datas.

i.e.) The listbox consists of 3 column(Year, Title, No).

Thanks


                   
0
 
LVL 9

Expert Comment

by:Volibrawl
ID: 6884087
Be sure that the name of the file that you want to open includes the path.  Here is a routine for a ComboBox where the path is in column2 and the filename is in column3:


Private Sub Combo0_AfterUpdate()
    Dim shellout As String
    shellout = "C:\windows\notepad.exe "
    shellout = shellout & Me.Combo0.Column(1)
    shellout = shellout & Me.Combo0.Column(2)

    Shell shellout
End Sub
0
 

Author Comment

by:jasonkk
ID: 6884094
xSinbad,

The listbox has 3 columns and sometimes the record is more than 1.
I need to know how to open file with Notepad when clicking on selected item based on 3rd column data from multiple datas.

i.e.) The listbox consists of 3 column(Year, Title, No).

Thanks


                   
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6884130
Private Sub Listbox1_DblClick(Cancel As Integer)
Shell "C:\WINDOWS\NOTEPAD.EXE" & Listbox1.Column(2, Listbox1.ListIndex)), 1
End Sub

will take the third column
0
 

Author Comment

by:jasonkk
ID: 6884161
I forgot to mention that the files are located in "C:\My Documents" directory and the file name is number which is "001" not "001.txt".
Thanks for your help
0
 
LVL 9

Accepted Solution

by:
Volibrawl earned 100 total points
ID: 6884183
1. It does not matter if the filename is .txt or not as long as you have the FULL actual filename to feed into the code.

2. If they are always in c:\mydocuments, just be sure you add that path into whichever solution you end up using.

3. In general, note that the 3rd column is column(2) BECAUSE the first column is alwayw column(0)


eg. bruintje's solution would be:

Private Sub Listbox1_DblClick(Cancel As Integer)
Shell "C:\WINDOWS\NOTEPAD.EXE c:\mydocuments\" & Listbox1.Column(2, Listbox1.ListIndex)), 1
End Sub


The combobox code would change to:

Private Sub Combo0_AfterUpdate()
   Dim shellout As String
   shellout = "C:\windows\notepad.exe c:\my documents\"
   shellout = shellout & Me.Combo0.Column(2)
   Shell shellout
End Sub




0
 
LVL 44

Expert Comment

by:bruintje
ID: 6884187
?

so something like

Private Sub Listbox1_DblClick(Cancel As Integer)
Shell "C:\WINDOWS\NOTEPAD.EXE" & "C:\My Documents\" & Listbox1.Column(2, Listbox1.ListIndex)) & "001", 1
End Sub

or is that number different every day/time? can it also be read from a box?

:O)Bruintje


0
 
LVL 44

Expert Comment

by:bruintje
ID: 6884191
correction "001" has to be ".001"
0
 

Author Comment

by:jasonkk
ID: 6884204
Thanks,

But, I have a small problem though with the way on opening the file.
Whenever it opens the file, it goes to background.
Do you know how to make it comes up in front.
0
 
LVL 9

Expert Comment

by:Volibrawl
ID: 6884210
Jason ... we are kind of guessing here. Can you provide us with this info ...

1. Is this a listbox (FOR SURE) or a combo box?
2. Type here EXACTLY what is in the 3rd column of any row
3. Type exactly the FileName of ANY of the files you want to open using notepad.  Include the extension if there is one.
4. If there is no extension on any of the files, how were they created?  Nearly every program tries to put an extension on its file names so you must have overridden it?





0
 
LVL 9

Expert Comment

by:Volibrawl
ID: 6884216
Well ignore my last post since we got it working.

No, I don't know how to make it come to the front, but I'll  try to find out.
0
 
LVL 9

Expert Comment

by:Volibrawl
ID: 6884231
Jason, the trailing ",1" causes it to open with the ocus, ",3" causes it to open maximized.

Which formula are you using to get to where you are?  We need to just add the ",1" to the end of it.
0
 
LVL 9

Expert Comment

by:Volibrawl
ID: 6884248
For Listbox1:

Private Sub Listbox1_DblClick(Cancel As Integer)
Shell "C:\WINDOWS\NOTEPAD.EXE " & "C:\My Documents\" & Listbox1.Column(2, Listbox1.ListIndex), 1
End Sub



OR for Combo0:

Private Sub Combo0_AfterUpdate()
   Shell ("C:\WINDOWS\NOTEPAD.EXE " & "C:\My Documents\" & Combo0.Column(2)), 1
   
End Sub

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

733 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