Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Filling/adding to a ComboBox

Status
Not open for further replies.

DJKAOS

Technical User
Jun 30, 2000
101
US
have a table but some entries are the same for example
my table might have
BOB
BOB
JOHN
SAM
BOB

I want to fill a combo box with these values but don't want reapeats in the combo box...so the combo box would have

BOB
JOHN
SAM

I tried spitting the table up and making relationships but it didn't work right.

Also how do you add entries to a combo box using VB Code?

Thakns
 
Use something like this as the rowsource for your combobox:

Select Distinct FirstName From NameTable Orderby FirstName

Good Luck!
 
THANKS!, that worked..but one more thing, when I select something new in the combo box I don't want it to write that value back to the table..I would like to be able to store the new selection in a variable though so I can use it later...mabye I should be doing this totally diffrent.

I thought making a table would be a good way to store certain values that I might need...mabye I should store them in a file instead? because I really dont use the table at all all it does is store some info basically.
 
The answer to your second question depends on what you are trying to accomplish. However, to answer your question generally, set the Limit To List property to Yes and then activate the On Not In List event for the combo box. This will give you access to the value typed in by the user.

Hope this helps!
 
I fixed it a diffrent way..I just don't have the form
assosiated with the table..it works fine now...now I'm stuck
on Opening files that dont exist yet.

like
Open "test.txt" for input as #1

gives me an error is test.txt doesn't exist...in C++ the open command creates the file if its not already there..how do I do this in VB?

 
Here is a function that I wrote for my applications. I think that it does what you are looking for.

Function folderExist(pathName As String)

' This function determines if a folder/file exists on the disk.
' The path name/file name to look for is passed in as a string.
' The function returns True if the folder exists and False if it doesn't exist.

' Usage: <booleanout> = folderExist(stringin)

Dim fs As Variant

Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)

If Dir(pathName, vbDirectory) = &quot;&quot; Then
folderExist = False
Else
folderExist = True
End If

End Function


Regarding your question about storing the value of a combo box in a variable, VB uses the Text or Value property of combo boxes, list boxes, text boxes, etc, to store the value. For example, if your combo box is named cboName and the user clicks on &quot;JOHN&quot;, cboName.Value will contain &quot;JOHN&quot;. You could also assign cboName.Value to another variable if you want.

Dim strName as String

strName = cboName.Value

You might check out the help on Dir as it has other options that I didn't discuss here.

Best,

dz

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top