Visual Basic ComboBox help
#1
Posted 14 June 2009 - 08:08 PM
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
#2
Posted 17 June 2009 - 07:30 AM
looney2340, on Jun 15 2009, 02:08 AM, said:
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?
Martin2k
Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows Vista Home Premium SP2 (laptop computer)
#3
Posted 17 June 2009 - 03:28 PM
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
#4
Posted 18 June 2009 - 06:14 AM
looney2340, on Jun 17 2009, 09:28 PM, said:
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.
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.
Martin2k
Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows Vista Home Premium SP2 (laptop computer)
#5
Posted 18 June 2009 - 05:10 PM
Thanks for the cudos on the right VB
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
#6
Posted 24 June 2009 - 05:09 AM
Something like this:
ShellExecute(Me.hwnd, "open","c:\myfile\demo.xls", "", "", 1)
More information on vbAccelerator:
http://www.vbaccelerator.com/codelib/shell/shellex.htm
#7
Posted 25 June 2009 - 04:24 PM
but it requires Excel to be Installed
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!
This post has been edited by chx101: 25 June 2009 - 04:25 PM
#8
Posted 01 July 2009 - 10:33 PM
Thanks again
#9
#10
Posted 02 July 2009 - 10:18 PM
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

Help



Back to top









