473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Open a given document based on selection within combo box

blyxx86
256 100+
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
11 5566
blyxx86
256 100+
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
32,556 Expert Mod 16PB
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
256 100+
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
32,556 Expert Mod 16PB
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
256 100+
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
32,556 Expert Mod 16PB
Thank you Blyxx86.
It's always nice to be appreciated ;)

Cheers -Adrian.
Dec 3 '06 #7
blyxx86
256 100+
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
256 100+
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
256 100+
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
32,556 Expert Mod 16PB
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
256 100+
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

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

Similar topics

1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
158
by: Giovanni Bajo | last post by:
Hello, I just read this mail by Brett Cannon: http://mail.python.org/pipermail/python-dev/2006-October/069139.html where the "PSF infrastracture committee", after weeks of evaluation, recommends...
6
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am thinking about doing this since I got several cases that some of our internal users open more than one browser at the same time from our server. When one of the transactions was not...
4
by: scolivas | last post by:
I think this is a me thing. but can't remember how to do it. I have a form that I am using and would like for a txt box to automatically populate based on what is selected in a combo box. here...
4
by: banderson | last post by:
Hello amazing vba writers, I am trying to make a combo box return a value based on a combo box selection. I have tried a number of the codes posted here and am still having problems. I think it is...
4
by: whamo | last post by:
I have the need to populate a field based on the selection in a combo box. Starting out simple. (2) tables tbl_OSE_Info and tbl_Input; tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt...
10
by: Beatrice | last post by:
I need to open a form selecting all data from a previous form i.e: Form 1) combo box 1 named "cboYearSelect" displayed as "Year" based on qry QryYearList ( only one field "Year") ...
1
by: peasedm | last post by:
Okay this one has me stumped. I have a table called Review_Statements with the following columns: statementid type statement1 statement2 statement3 I have a form called SR_Review with an...
8
by: Jharp | last post by:
Ok, so im really new to access and programing in general, what i am doing is building a inventory(something simple), the way ive got it set up now is, my entire inventory is in a combo box, and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.