Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Open Notepad from listbox

Posted on 2002-03-20
18
Medium Priority
?
387 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
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

972 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