Is it possible to have multiple columns in a combo box? Any help would be great. thanks in advance
Printable View
Is it possible to have multiple columns in a combo box? Any help would be great. thanks in advance
Hello dionj,
Here is a part of a source to fill a combobox with information from two fields from a database, delimitted by "|"
Private Sub Form_Load()
DbSetting = "f:\BB.mdb"
Set DB = OpenDatabase(DbSetting)
Set RS = DB.OpenRecordset("select * from YourTable")
LenName = 0
LenFirstName = 0
RS.MoveFirst
While Not RS.EOF 'searching for the longest string
If Len(RS("Name")) > LenName Then LenName = Len(RS("Name"))
If Len(RS("FirstName")) > LenFirstName Then LenFirstName = Len(RS("FirstName"))
RS.MoveNext
Wend
RS.MoveFirst
While Not RS.EOF
Combo1.AddItem Left(RS("Name") + Space(LenName + 2), (LenName + 2)) & "| " & RS("FirstName") + Space(LenFirstName + 2)
RS.MoveNext
Wend
Combo1.Text = Combo1.List(0)
End Sub
IMPORTANT: THIS WILL ONLY GOES WELL IF ALL CHARACTERS OF THE COMBO TEXTSTYLE DO HAVE THE SAME DISTANCE! (PROPORTIONAL)
Michelle.
Thanks for the idea, but I was hoping on being able to do it without having to pad the columns with spaces, and besides the informatin for the combo box is coming form a database with over 10,000 records so finding the longest and padding the other records would be inefficient