|
 |
access thread: ComboBox
Message #1 by "Olivier Hamel" <hamel_olivier@h...> on Tue, 21 Jan 2003 18:42:14
|
|
I want to pfill my combobox with 2 fields from a table (TableSite
The ID and the Name
but i want the ID part of my combobox to be invisible.
What's the VBA code to do so ??
To fill it and to make the first column invisible.
I was filling my combo this way :
strSQL="SELECT TableSite.ID,TableSite.Name FROM TableSite"
set DB=Application.CurrentdDB
set RS=DB.OpenRecordset(strSQL)
Do
ComboBox.AddItem(RS.Fields("ID").value,0)
ComboBox.AddItem(RS.Fields("Name").value,1)
RS.MobeNext
Loop until RS.EOF = true
And it's not working. I'm sure i'm doing wrong but i don't know where :-(
Message #2 by "Gregory Serrano" <SerranoG@m...> on Tue, 21 Jan 2003 19:00:13
|
|
Oliver,
<< I want to pfill my combobox with 2 fields from a table (TableSite
The ID and the Name but i want the ID part of my combobox to be invisible.
What's the VBA code to do so ?? To fill it and to make the first column
invisible. >>
Fill the combobox like you normally do, but you don't have to code the ID
column. Merely select the combobox in design view and set the column
width property to 0; 1. This will make the first column invisible.
Greg
Message #3 by "John Ruff" <papparuff@a...> on Tue, 21 Jan 2003 10:48:03 -0800
|
|
If you go to Help and search Combobox you will find all the info you
need to
fill the comobobox.
But, in a nutshell, you need to use four properties of the combobox and
they
are RowSource, Column Count, Bound Column, and Column Widths.
RowSource=3D"SELECT TableSite.ID,TableSite.Name FROM TableSite"
' This will fill the combobox with all the IDs and Names from your table
Column Count=3D2
' Tells the combobox how many columns to use
Bound Column=3D1
' Tells the combobox that column one is the column you will use to do
searches.
Column Widths=3D0; 2;
' Tells the combobox that the first column(ID) is 0" in width (making it
unseen to the user), and that the second column(Name) is 2" in width.
John V. Ruff - The Eternal Optimist :-)
Always Looking For Contract Opportunities
www.noclassroom.com
Live software training
Right over the Internet
Home: xxx.xxx.xxxx
Cell: 253.307/2947
9306 Farwest Dr SW
Lakewood, WA 98498
"Commit to the Lord whatever you do,
and your plans will succeed." Proverbs 16:3
-----Original Message-----
From: Olivier Hamel [mailto:hamel_olivier@h...]
Sent: Tuesday, January 21, 2003 6:42 PM
To: Access
Subject: [access] ComboBox
I want to pfill my combobox with 2 fields from a table (TableSite The ID
and
the Name
but i want the ID part of my combobox to be invisible.
What's the VBA code to do so ??
To fill it and to make the first column invisible.
I was filling my combo this way :
strSQL=3D"SELECT TableSite.ID,TableSite.Name FROM TableSite"
set DB=3DApplication.CurrentdDB
set RS=3DDB.OpenRecordset(strSQL)
Do
ComboBox.AddItem(RS.Fields("ID").value,0)
ComboBox.AddItem(RS.Fields("Name").value,1)
RS.MobeNext
Loop until RS.EOF =3D true
And it's not working. I'm sure i'm doing wrong but i don't know where
:-(
Message #4 by "Olivier Hamel" <hamel_olivier@h...> on Tue, 21 Jan 2003 19:06:26
|
|
> Oliver,
> << I want to pfill my combobox with 2 fields from a table (TableSite
T> he ID and the Name but i want the ID part of my combobox to be
invisible.
W> hat's the VBA code to do so ?? To fill it and to make the first column
i> nvisible. >>
> Fill the combobox like you normally do, but you don't have to code the
ID
c> olumn. Merely select the combobox in design view and set the column
w> idth property to 0; 1. This will make the first column invisible.
> Greg
But do you have an example of setting the columnwidth.
I'm doing this : comboBox.ColumnWidths "0;1cm"
And it's giving me the error Invalid use of property.
So give me an example please ;-)
Message #5 by "John Ruff" <papparuff@a...> on Tue, 21 Jan 2003 11:08:46 -0800
|
|
Oliver,
If you want to populate a combobox via code you do not have to open a
recordset; all you need is the SQL statement. If you take the info I
provided in my last email, here is how it looks in code:
With YourComboBox
' Fills the combobox with all the IDs and Names from your table
.RowSource="SELECT TableSite.ID,TableSite.Name FROM TableSite"
' How many columns to use
.ColumnCount=2
' Which column is the "Bound" column
BoundColumn=1
' Sets the width of both columns
ColumnWidths="0;2"
End With
John V. Ruff - The Eternal Optimist :-)
Always Looking For Contract Opportunities
www.noclassroom.com
Live software training
Right over the Internet
Home: xxx.xxx.xxxx
Cell: 253.307/2947
9306 Farwest Dr SW
Lakewood, WA 98498
"Commit to the Lord whatever you do,
and your plans will succeed." Proverbs 16:3
-----Original Message-----
From: Olivier Hamel [mailto:hamel_olivier@h...]
Sent: Tuesday, January 21, 2003 7:06 PM
To: Access
Subject: [access] Re: ComboBox
> Oliver,
> << I want to pfill my combobox with 2 fields from a table (TableSite
T> he ID and the Name but i want the ID part of my combobox to be
invisible.
W> hat's the VBA code to do so ?? To fill it and to make the first
W> column
i> nvisible. >>
> Fill the combobox like you normally do, but you don't have to code the
ID
c> olumn. Merely select the combobox in design view and set the column
w> idth property to 0; 1. This will make the first column invisible.
> Greg
But do you have an example of setting the columnwidth.
I'm doing this : comboBox.ColumnWidths "0;1cm"
And it's giving me the error Invalid use of property.
So give me an example please ;-)
Message #6 by "John Fejsa" <John.Fejsa@h...> on Wed, 22 Jan 2003 09:27:42 +1100
|
|
You can actually set it directly on your combo box.
1) Click required combo box to select it
2) Open Properties dialogue box
3) Click Format tab
4) Type 0cm, 10cm in Column Widths text box
This will set the ID column of you combo box to zero centimetres
(consequently, invisible) and Name column to 10 centemetres (the only
one visible)
To set it in Visual Basic use ColumnWidths like:
Me!cmbMyComboBox.ColumnWidths ="0; 2.5 in"
This will set the first column to zero (invisible) and second to 2.5
inches (old imperial measuring system)
To separate your column entries, use semicolons (;) as list separators
Hope that was helpful...
____________________________________________________
John Fejsa
Systems Analyst/Computer Programmer
Hunter Centre for Health Advancement
Locked Bag 10, WALLSEND NSW 2287
Phone: (02) 4924 6336 Fax: (02) 4924 6209
www.hcha.org.au
____________________________________________________
The doors we open and close each day decide the lives we live
____________________________________________________
CONFIDENTIALITY & PRIVILEGE NOTICE
>>> hamel_olivier@h... 22/01/2003 5:42:14 >>>
I want to pfill my combobox with 2 fields from a table (TableSite
The ID and the Name
but i want the ID part of my combobox to be invisible.
What's the VBA code to do so ??
To fill it and to make the first column invisible.
I was filling my combo this way :
strSQL="SELECT TableSite.ID,TableSite.Name FROM TableSite"
set DB=Application.CurrentdDB
set RS=DB.OpenRecordset(strSQL)
Do
ComboBox.AddItem(RS.Fields("ID").value,0)
ComboBox.AddItem(RS.Fields("Name").value,1)
RS.MobeNext
Loop until RS.EOF = true
And it's not working. I'm sure i'm doing wrong but i don't know where
:-(
This message is intended for the addressee named
and may contain confidential information.
If you are not the intended recipient, please
delete it and notify the sender.
Views expressed in this message are those of the
individual sender, and are not necessarily the
views of Hunter Health.
|
|
 |