Help - Search - Members - Calendar
Full Version: Visual Basic
BleepingComputer.com > Software > Programming
   
looney2340
Hi everyone,

Im writting a program and i have a combo box on a form that is populated from a text file and it works. Can anyone help me with the code on when i click on a name in the combo box i need it to open an excel form associated with that particular name. The list will contain approx 100 names and each one will have its own excel form. I have been searching and can not find anything anywhere to help me.

Thanks
Keithuk
QUOTE(looney2340 @ Jun 15 2009, 02:08 AM) *
Im writting a program and i have a combo box on a form that is populated from a text file and it works. Can anyone help me with the code on when i click on a name in the combo box i need it to open an excel form associated with that particular name. The list will contain approx 100 names and each one will have its own excel form. I have been searching and can not find anything anywhere to help me.


First off it will depend on which VB you are using VB6 or VB.Net?

A ComboBox with filenames in will only work in the App.Path unless you show the location if the file its somewhere else.

If you're only showing filenames in the ComboBox then why don't you just use the CommonDialogl control or ComDlg32.dll API calls to find an Excel file? dry.gif
looney2340
Hi Keith,

Thanks for the reply i am writting this for a friend to use with her busniess.....i havent used vb in such a long time so im starting almost from the beginning.......i am using VB6 Enterprise edition i am not showing the file names of the specific excel file in the combo box only names of people from a text file and when i click on it i need an excel file to open that is associated with it as of now im not sure what the names of the excel files would be so i just made one to test the program with.....if that make sense LoL....i have never used API calls but have been doing some reading about it.
Isnt there a way to use .....list.index so when i click on a name in the list i can get it to open the needed file ?

I hope i dont sound to much like a beginner just finding my way back into VB.

Thanks for the help
Keithuk
QUOTE(looney2340 @ Jun 17 2009, 09:28 PM) *
i am using VB6 Enterprise edition i am not showing the file names of the specific excel file in the combo box only names of people from a text file and when i click on it i need an excel file to open that is associated with it as of now im not sure what the names of the excel files would be so i just made one to test the program with.....if that make sense LoL....i have never used API calls but have been doing some reading about it.
Isnt there a way to use .....list.index so when i click on a name in the list i can get it to open the needed file ?


Ok I see you're using proper VB, good job. thumbup2.gif

So this text file will have names in that you can select from the ComboBox and it will open an Excel file and show that name in a particular cell and any more info thats needed?

Now depending on how you do this you may need Excel installed on the computer you are running your app from. Or you can just reference it. dry.gif
looney2340
Hi keith,

Thanks for the cudos on the right VB smile.gif

Yes the combo box is populated with names from a txt file but i dont need the name chosen in the combo box to be added into a cell in an excel file.....what i need is an excel file that already has info in it to open...and the computer the app will be on does have excel on it here is the code i will use to open excel i have it already in a command button for something else ..


Dim oXLApp As Excel.Application
Dim oxlbook As Excel.Workbook
Set oXLApp = New Excel.Application
Set oxlbook = oXLApp.Workbooks.Open("C:\Users\Henry\Desktop\FILENAME.xls") <~~~~~THIS WOULD BE THE PATH OF THE FILE I WOULD NEED OPENED
oXLApp.Visible = True

Set oxlbook = Nothing
Set oXLApp = Nothing
End Sub

My problem is when i click on a name in the combo list i dont know how to code it so it opens the appropiate file i was trying the click event of the combo box but it opens the same file no matter where i click or what name because its the click event i hope im explaining what i need the right way. Im hope im not confusing you in what i need. LoL

The common dialog box is ok but im trying to make easier for my friend so all she has to do is click a patients name in a list and the file she needs opens for her....she needs it as simple as possible i was also thinking either a check box and command button or option button when chosen automatically opens the file needed but that would involve at least 100 buttons which i can code ok but would be a bit time consuming.

Thanks for the patience
Romeo29
If the computer has MS Excel installed, then simply use ShellExecute() to launch the respective excel file.
Something like this:
ShellExecute(Me.hwnd, "open","c:\myfile\demo.xls", "", "", 1)

More information on vbAccelerator:
http://www.vbaccelerator.com/codelib/shell/shellex.htm
chx101
try this i

but it requires Excel to be Installed

CODE

sub whatever_the_Combobox_event_is(events in here)

' the file that has been selected in the ComboBox
Dim FileN As New IO.FileInfo(ComboBox1.selectedItem) 'if there's an error add .ToString()

'check the file extension
Dim FileExt
Dim FileNameFull
FileNameFull = My.Computer.SystemFile.File(FileN).FullName
FileExt = My.Computer.SystemFile.File(FileN).Exstension

'if extension is Excel extension it will open the file as a new process, else error
if FileExt = ".xls" then

'Processe must have full path to its files, so
Process.Start(FileNameFull)

'we dont want an error so instead
Else If FileExt Is Not ".xls" then 'or use <> to replace Is Not

shell("Rundll32 Shell32.dll,OpenAs_ RunDLL " & FileNameFull,vbNormalFocus,false)

End if





so what this does :
when you click select the file from the ComboBox it will check the file extension too see if its an excel sheet file extension
and if not it will bring up the Windows "Open With Dialog Box"

But Make Sure your ComboBox TextBox is Uneditable to avoid "file Not Found Error" and that the selected Item index is set to 0 to remove the Blank Space...You have to write this in the Form1_Load()

I think that will help, Good Luck!
looney2340
Thank you Chx for the reply i have been away and just read your post i will give it a try and let you know how i make out

Thanks again
Romeo29
QUOTE(chx101 @ Jun 25 2009, 05:24 PM) *
try this i

but it requires Excel to be Installed
......


If you read the whole topic you would find the person who asked the question is using VB6. The code you posted is in VB.NET. wacko.gif
looney2340
Hi romeo,

I was wondering why the code looked a little odd and couldnt get it to work properly...if anyone can help with a simple copy and past code it would be much appreciated....in the mean time ill keep plugging away with some new ideas on my own..

Thanks for the help
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.