Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box VB Question & SW 2

Status
Not open for further replies.

RC2003

Mechanical
Feb 4, 2003
5
I am in need of the code required to add a simple combo box to an existing macro. I would like to have the abilty to select an individual user name from a A pull down list.

Also is there an easy way to force upper case text in a text box?

Please be as descriptive and possibly provide the code as I am just beginning VB and have no clue.

Not sure if it's important but all of my code for the macro is associated with the userform.
 
Replies continue below

Recommended for you

Combobox works like it does for jsut about any other VBA app. Just drag one in to the form when in the VB editor environment and set it up.

[bat]All this machinery making modern music can still be open hearted.[bat]
 
RC2003

Like the Tick said you insert the combobox into the form. Then in the vb editor enter:

'fill cbo box
'cbo_byl is the name of the combo box on the form
cbo_byl.AddItem " "
cbo_byl.AddItem "DH"
cbo_byl.AddItem "CB"
cbo_byl.AddItem "LAN"
 
You can force the text to upper case using the UCase(String) function. For example, if you wanted the text in TextBox1 to convert to upper case you would write TextBox1.Value = UCase(TextBox1.Value).
 
If correctly parsing variables is your goal here (Im assuming you are capitalizing so you only have to do one string comparison) use a ListBox instead of a ComboBox.

The combobox will/can allow them to type in their own entries, and to catch THAT requires a lot more work.
 
The mistake I made when writing our Title Box VB program. I put the engineers, designers, and drafter’s names in a list box instead of outside the program in a text file. Now only I can add names to the automatically filled in text box. Bad move. I also put the finishes, materials, and material sizes in code. Now every change has to be done by me. If you are just starting get a good VB box and write data that will change outside the VB code.
Good luck.


Bradley
 
Bradley's suggestion is a good one. The whole point of using a vb routine to enter custom properties instead of using the SWX interface is that the user can have list boxes, combo boxes and radio buttons etc to help minimize the amount of manual data entry. If you hard code the data into the program then someone has to maintain the lists. The better solution is to hold the data in a text file and let the user customize the file. The vb routine can then look for the text file and populate the controls accordingly.

There are a couple of examples on the SWX website which can help you with this project. There is a vb custom property program in the model library which you can easily customize. I went a step further and integrated the custom property code into the SWX property manager page instead of using a separate form. I like this approach because it is completely integrated with the parent program. There is also an example showing how to create a property manager page using vba in the api section of the SWX website.
 
Another way to force upper case is to put this statement:

KeyAscii = Asc(UCase$(Chr$(KeyAscii)))

into the combo box KeyPress event. That way the user will only see upper case letters as they are typed.

Regg [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor