Solved

Open Notepad from listbox

Posted on 2002-03-20
18
367 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
  • 6
  • 5
  • 4
  • +2
18 Comments
 
LVL 6

Expert Comment

by:xSinbad
Comment Utility
You should use the shell command;

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

Expert Comment

by:xSinbad
Comment Utility
That should be

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

Expert Comment

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

Nic;o)
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
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
Comment Utility
Private Sub Listbox1_DblClick(Cancel As Integer)
 Shell "C:\WINDOWS\NOTEPAD.EXE" & Listbox1.ItemData(Listbox1.ListIndex), 1
End Sub

0
 

Author Comment

by:jasonkk
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:jasonkk
Comment Utility
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
Comment Utility
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
Comment Utility
?

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
Comment Utility
correction "001" has to be ".001"
0
 

Author Comment

by:jasonkk
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

7 Experts available now in Live!

Get 1:1 Help Now