By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,560 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,560 IT Pros & Developers. It's quick & easy.

Open a given document based on selection within combo box

blyxx86
100+
P: 256
Alright, I'm trying to create a form that would allow certain documents to be opened by selecting an option within a combo box and then having a single button to open the pertaining file.

I know how to have it open an excel document (or word, etc.) but do not know how to define which document to open.

Expand|Select|Wrap|Line Numbers
  1.     Dim ExApp As Object
  2.     Set ExApp = CreateObject("Excel.Application")
  3.     ExApp.Workbooks.Open FileName:="c:\file.xls", ReadOnly:=True
  4.     ExApp.Visible = True
  5.  
How would I define this to open up within Wordpad (or another basic text program.) Would it be: CreateObject "Wordpad.Application" (i typed 'wordpad' into the run and it showed up, so i'm guessing it would.)

Also, how would I define that when
cboFile = "Model Information 1" to open file: "\\Network Drive\docs\mod1.doc"
cboFile= "Model Information 2" to open file: "\\Network Drive\docs\mod2.doc"
etc...

Would it be an extraneous series of IF THEN statements?
Dec 2 '06 #1
Share this Question
Share on Google+
11 Replies


blyxx86
100+
P: 256
Did I make the issue obfuscated? If so, please let me know so I can clear up any ambiguity or general confusion.
Dec 2 '06 #2

NeoPa
Expert Mod 15k+
P: 31,602
You can only open up a doc using the method you've outlined IF there is a library to reference for that application.
There may well be ones for Notepad & Wordpad, I don't know.
I would imagine that setting the document name using a UNC (Universal Naming Convention) would comprise simply putting the full ref in quotes exactly as you do with a drive letter referenced one.
Don't do much of this myself.
Dec 3 '06 #3

blyxx86
100+
P: 256
You can only open up a doc using the method you've outlined IF there is a library to reference for that application.
There may well be ones for Notepad & Wordpad, I don't know.
I would imagine that setting the document name using a UNC (Universal Naming Convention) would comprise simply putting the full ref in quotes exactly as you do with a drive letter referenced one.
Don't do much of this myself.
What about having it run a command based on what I've chosen in a combo box?

IF cboFiles = "Model 1" Then Filename="c:\model1.txt"
ElseIF cboFiles = "Model 2" Then filename="c:\model2.txt"
Else
End If
etc...?? I doubt i've structured that properly, but is something like that a possibility?
Dec 3 '06 #4

NeoPa
Expert Mod 15k+
P: 31,602
You should be able to use the Shell() function, certainly.
Instead of your If statement you can use the Select Case statement and, if really clever, you can set one column to display in your ComboBox and another (command) column to be returned as the value and just pass the value of the ComboBox directly to the Shell() function.
Dec 3 '06 #5

blyxx86
100+
P: 256
You should be able to use the Shell() function, certainly.
Instead of your If statement you can use the Select Case statement and, if really clever, you can set one column to display in your ComboBox and another (command) column to be returned as the value and just pass the value of the ComboBox directly to the Shell() function.
That is clever.

I'll look into that for sure. The place I'm working at currently went from a $1million yearly company to over $25million in the past year and haven't quite figured out how to keep things organized or develop any processes for anything. That's my job.

I'm hoping this will work, otherwise I'll just have to put out an e-mail about the shared drive. :)

Silly people.
Dec 3 '06 #6

NeoPa
Expert Mod 15k+
P: 31,602
Thank you Blyxx86.
It's always nice to be appreciated ;)

Cheers -Adrian.
Dec 3 '06 #7

blyxx86
100+
P: 256
Thank you Blyxx86.
It's always nice to be appreciated ;)

Cheers -Adrian.
Hmmm, question though...

what is the Shell() command?

Haha
Dec 3 '06 #8

blyxx86
100+
P: 256
Hmmm, question though...

what is the Shell() command?

Haha
Actually, it's a very easy to use command...

Now I just have to figure out how to link it to a listbox.

I'll post my code in a minute.
Dec 3 '06 #9

blyxx86
100+
P: 256
Okay, everything seemed to work just fine, now I want to be able to set it as readonly.

I have..

Expand|Select|Wrap|Line Numbers
  1. Dim RetOpen
  2. Dim RetFile As String
  3. RetFile = Forms!frmName.[ListBoxName].Column(2) & " " & Forms!frmName.[ListBoxName].Column(1)
  4.  
  5. RetOpen = Shell(RetFile, 1)
  6.  
  7. End Sub
  8.  
I feel like I'm understanding a bit more.

this gets two columns (Column(2)) is the App used to open the program (ie. Notepad.exe) and (Column(1)) is the whole filename (ie. C:\Text.txt)

Bare in mind, that column(2) is my app and that Column(1) is my file.

These translate to column 3 and column 2 within the actual table.

I feel good now.

**I had to put a space between the app and the filename but forgot to put an '&' between the space and the filename so I kept getting End of Statement errors.
Dec 3 '06 #10

NeoPa
Expert Mod 15k+
P: 31,602
Sounds like you're really getting there Blyxx86. Question for you though.
Is your code within the form that you're referring to?
If so, you needn't give the full reference but can use Me. for the form part of the reference.
Expand|Select|Wrap|Line Numbers
  1. Dim RetOpen
  2. Dim RetFile As String
  3. RetFile = Me.[ListBoxName].Column(2) & " " & Me.[ListBoxName].Column(1)
  4.  
  5. RetOpen = Shell(RetFile, 1)
  6.  
  7. End Sub
Dec 4 '06 #11

blyxx86
100+
P: 256
Sounds like you're really getting there Blyxx86. Question for you though.
Is your code within the form that you're referring to?
If so, you needn't give the full reference but can use Me. for the form part of the reference.
Expand|Select|Wrap|Line Numbers
  1. Dim RetOpen
  2. Dim RetFile As String
  3. RetFile = Me.[ListBoxName].Column(2) & " " & Me.[ListBoxName].Column(1)
  4.  
  5. RetOpen = Shell(RetFile, 1)
  6.  
  7. End Sub
I am using "Me" statements, but decided to leave it without the Me. when i posted, so it's more of a concrete type. I'm also figuring out how to structure my tables better. Slowly but surely.
Dec 4 '06 #12

Post your reply

Sign in to post your reply or Sign up for a free account.