473,756 Members | 7,817 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HOWTO: use RowSource property of a field in MS Access table

Hello,

I have a table in MS Access database. It has one field (with BYTE datatype)
that has several properties set in Lookup tab of table Design View.
Display Control = Combo Box. Row Source Type = Value List. Row Source = "1;
"Above"; 2; "Below"; 3; "Equal"".
When I try to SELECT <field> FROM <table> in my C++ application through ADO,
I get numeric value of the field. How can I get string representation of
this numeric value from the Row Source property? The code is below:

CString tmp;
_RecordsetPtr pRs("ADODB.Reco rdset");
tmp = "select field from table"; // query
pRs->Open((_bstr_t) tmp, _variant_t((IDi spatch*)pGWMCon n, true),
adOpenForwardOn ly, adLockReadOnly, adCmdText); // open recordset
tmp = (LPCTSTR)(_bstr _t)pRs->Fields->Item["field"]->Value; // get
numeric value (string from Row Source is needed)
pRs->Close();

Regards,
Vladimir.


Nov 12 '05 #1
8 20354
The properties you mention only apply to how the table is represented in
the in datasheet view interface in Access. In any other context, you
should use a query join to get the data from the other table.

In some cases, it's better to put the whole SQL statement in the code. In
other cases, it's better to save a querydef (Procedure in ADO parlance)
that encapsulates the query/join. Take your pick.

On Tue, 16 Sep 2003 01:33:48 +0600, "Vladimir" <ge******@ufaco m.ru> wrote:
Hello,

I have a table in MS Access database. It has one field (with BYTE datatype)
that has several properties set in Lookup tab of table Design View.
Display Control = Combo Box. Row Source Type = Value List. Row Source = "1;
"Above"; 2; "Below"; 3; "Equal"".
When I try to SELECT <field> FROM <table> in my C++ application through ADO,
I get numeric value of the field. How can I get string representation of
this numeric value from the Row Source property? The code is below:

CString tmp;
_RecordsetPtr pRs("ADODB.Reco rdset");
tmp = "select field from table"; // query
pRs->Open((_bstr_t) tmp, _variant_t((IDi spatch*)pGWMCon n, true),
adOpenForwardO nly, adLockReadOnly, adCmdText); // open recordset
tmp = (LPCTSTR)(_bstr _t)pRs->Fields->Item["field"]->Value; // get
numeric value (string from Row Source is needed)
pRs->Close();

Regards,
Vladimir.


Nov 12 '05 #2
Vladimir wrote:
Row Source = "1; "Above"; 2; "Below"; 3; "Equal"".
When I try to SELECT <field> FROM <table> in my C++ application
through ADO, I get numeric value of the field. How can I get
string representation of this numeric value from the Row Source
property?


You don't. It doesn't exist in the table, ONLY in the Access Form
(specifically, in the ComboBox). I assume the BoundColumn prop is
set to 1. That means that when a user selects an item from the CB,
the first column's value is put in the database field. The second
column values (the strings) never leave the CB.

You have two choices:

Ideal: create a new table containing the CB Row Source values, and
use that to populate the CB. When you open a recordset, open an
SQL query that joins the main table to the new table and select
the field containing the strings.

Workable: Re-create the Row Source data in your C++ application
and translate from the numeric value to the string.

--
|_ CJSonnack <Ch***@Sonnack. com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ _______________ ____| Call: 1-800-DEV-NULL |
|______________ _______________ _______________ _|_____________ __________|
Nov 12 '05 #3
Hello,

But why can't I get access to Properties collection of Field object? In
Access Help I've read that I can set these (RowSource and others) properties
through VB. Why can't I do this in my C++ app? Also when I execute query
SELECT <field> FROM <table> in Access Query Designer I get string. When I
execute through ADO I get number.

The problem is that I don't know if Row Source string array will never be
changed. If I place this array in my app I will then need to make changes to
source code and re-compile the program.

The "Ideal" way is also unacceptable because the users of my app will need
to add this new table to the database every time it is replaced by new one
(which is without this table). I mean replacing whole MDB files.

Regards,
Vladimir.

Programmer Dude <cj*******@mmm. com> ïèøåò â
ñîîáùåíèè:3F*** ************@mm m.com...
Vladimir wrote:
Row Source = "1; "Above"; 2; "Below"; 3; "Equal"".
When I try to SELECT <field> FROM <table> in my C++ application
through ADO, I get numeric value of the field. How can I get
string representation of this numeric value from the Row Source
property?


You don't. It doesn't exist in the table, ONLY in the Access Form
(specifically, in the ComboBox). I assume the BoundColumn prop is
set to 1. That means that when a user selects an item from the CB,
the first column's value is put in the database field. The second
column values (the strings) never leave the CB.

You have two choices:

Ideal: create a new table containing the CB Row Source values, and
use that to populate the CB. When you open a recordset, open an
SQL query that joins the main table to the new table and select
the field containing the strings.

Workable: Re-create the Row Source data in your C++ application
and translate from the numeric value to the string.

--
|_ CJSonnack <Ch***@Sonnack. com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ _______________ ____| Call: 1-800-DEV-NULL |
|______________ _______________ _______________ _|_____________ __________|

Nov 12 '05 #4
The properties are not stored in the normal table attributes, they're
stored in special Document structures used by Access alone. Even if you
-could- read the properties, you'd still have to parse out the combo box
query text, and run it in your own code to get the related value since
Combo boxes are Access GUI constructs, and not part of tables or query
results directly.

On Tue, 16 Sep 2003 12:10:54 +0600, "Vladimir" <ge******@ufaco m.ru> wrote:
Hello,

But why can't I get access to Properties collection of Field object? In
Access Help I've read that I can set these (RowSource and others) properties
through VB. Why can't I do this in my C++ app? Also when I execute query
SELECT <field> FROM <table> in Access Query Designer I get string. When I
execute through ADO I get number.

The problem is that I don't know if Row Source string array will never be
changed. If I place this array in my app I will then need to make changes to
source code and re-compile the program.

The "Ideal" way is also unacceptable because the users of my app will need
to add this new table to the database every time it is replaced by new one
(which is without this table). I mean replacing whole MDB files.

Regards,
Vladimir.

Programmer Dude <cj*******@mmm. com> ïèøåò â
ñîîáùåíèè:3F** *************@m mm.com...
Vladimir wrote:
> Row Source = "1; "Above"; 2; "Below"; 3; "Equal"".
> When I try to SELECT <field> FROM <table> in my C++ application
> through ADO, I get numeric value of the field. How can I get
> string representation of this numeric value from the Row Source
> property?


You don't. It doesn't exist in the table, ONLY in the Access Form
(specifically, in the ComboBox). I assume the BoundColumn prop is
set to 1. That means that when a user selects an item from the CB,
the first column's value is put in the database field. The second
column values (the strings) never leave the CB.

You have two choices:

Ideal: create a new table containing the CB Row Source values, and
use that to populate the CB. When you open a recordset, open an
SQL query that joins the main table to the new table and select
the field containing the strings.

Workable: Re-create the Row Source data in your C++ application
and translate from the numeric value to the string.

--
|_ CJSonnack <Ch***@Sonnack. com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ _______________ ____| Call: 1-800-DEV-NULL |
|______________ _______________ _______________ _|_____________ __________|


Nov 12 '05 #5
Vladimir wrote:
But why can't I get access to Properties collection of Field object?
You can. Row Source is *NOT* a property of a Field. It's a property
of the ComboBox on the Form in Access.
Also when I execute query SELECT <field> FROM <table> in Access
Query Designer I get string. When I execute through ADO I get
number.
Are you saying you get "Above" in that case and "1" if you issue
an SQL statement through VC++? That's.... impossible. Something
else is going on. Are you sure the Query Designer isn't linking
in a table or doing some sort of lookup?

Take a look under the hood of that query and maybe look at the
definition of the table in question. Access can link to lookup
tables--did you design the database or did someone else?
The problem is that I don't know if Row Source string array will
never be changed. If I place this array in my app I will then need
to make changes to source code and re-compile the program.
That's why it's non-ideal. You could use an external text file to
initialize your program. That would save re-compiling.
The "Ideal" way is also unacceptable because the users of my app
will need to add this new table to the database every time it is
replaced by new one (which is without this table). I mean
replacing whole MDB files.


I take it you are not supplying the MDB files (else you could just
add it yourself).
--
|_ CJSonnack <Ch***@Sonnack. com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ _______________ ____| Call: 1-800-DEV-NULL |
|______________ _______________ _______________ _|_____________ __________|
Nov 12 '05 #6
Hello,

Programmer Dude <Ch***@Sonnack. com> ïèøåò â
ñîîáùåíèè:3F*** ************@So nnack.com...
Vladimir wrote:
But why can't I get access to Properties collection of Field object?
You can. Row Source is *NOT* a property of a Field. It's a property
of the ComboBox on the Form in Access.


Then how can I get those sort of properties?
Also when I execute query SELECT <field> FROM <table> in Access
Query Designer I get string. When I execute through ADO I get
number.


Are you saying you get "Above" in that case and "1" if you issue
an SQL statement through VC++? That's.... impossible. Something
else is going on. Are you sure the Query Designer isn't linking
in a table or doing some sort of lookup?


It is possible. You can create your own table in Access with one field
having lookup with following properties:

Display control = Combo Box
Row ource type = Value list
Row source = 1;"qwe";2;"asd" ;3;"zxc"
Bound column = 1
Column count = 2
Column heads = No
Column widths = 0cm;4cm
List rows = 8
List width = 4cm
Limit to list = Yes

Then fill table with data and enter MANUALLY in Query Designer (View / SQL
mode) this text: SELECT <field> FROM <table> - and you will get strings.
Take a look under the hood of that query and maybe look at the
definition of the table in question. Access can link to lookup
tables--did you design the database or did someone else?


I'm not but I've tried to design table as described above.

Regards,
Vladimir.
Nov 12 '05 #7
Yet again, I correct myself. The properties are available through the
containers/documents collection of the DAO database object, and therefore
they are available outside of Access, though the code that makes use of
this data to display a combo box in datasheed view and look up a matching
row in another table belonce solely to Access.

I'm assuming this is one of those cases where DAO has some capabilities
with JET databases that ADO does not, but they might be accessible as
metadata using the ADOX library. It's worth a try, I suppose.

On Tue, 16 Sep 2003 07:12:43 GMT, Steve Jorgensen <no****@nospam. nospam>
wrote:
The properties are not stored in the normal table attributes, they're
stored in special Document structures used by Access alone. Even if you
-could- read the properties, you'd still have to parse out the combo box
query text, and run it in your own code to get the related value since
Combo boxes are Access GUI constructs, and not part of tables or query
results directly.

On Tue, 16 Sep 2003 12:10:54 +0600, "Vladimir" <ge******@ufaco m.ru> wrote:
Hello,

But why can't I get access to Properties collection of Field object? In
Access Help I've read that I can set these (RowSource and others) properties
through VB. Why can't I do this in my C++ app? Also when I execute query
SELECT <field> FROM <table> in Access Query Designer I get string. When I
execute through ADO I get number.

The problem is that I don't know if Row Source string array will never be
changed. If I place this array in my app I will then need to make changes to
source code and re-compile the program.

The "Ideal" way is also unacceptable because the users of my app will need
to add this new table to the database every time it is replaced by new one
(which is without this table). I mean replacing whole MDB files.

Regards,
Vladimir.

Programmer Dude <cj*******@mmm. com> ïèøåò â
ñîîáùåíèè:3F* **************@ mmm.com...
Vladimir wrote:

> Row Source = "1; "Above"; 2; "Below"; 3; "Equal"".
> When I try to SELECT <field> FROM <table> in my C++ application
> through ADO, I get numeric value of the field. How can I get
> string representation of this numeric value from the Row Source
> property?

You don't. It doesn't exist in the table, ONLY in the Access Form
(specifically, in the ComboBox). I assume the BoundColumn prop is
set to 1. That means that when a user selects an item from the CB,
the first column's value is put in the database field. The second
column values (the strings) never leave the CB.

You have two choices:

Ideal: create a new table containing the CB Row Source values, and
use that to populate the CB. When you open a recordset, open an
SQL query that joins the main table to the new table and select
the field containing the strings.

Workable: Re-create the Row Source data in your C++ application
and translate from the numeric value to the string.

--
|_ CJSonnack <Ch***@Sonnack. com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ _______________ ____| Call: 1-800-DEV-NULL |
|______________ _______________ _______________ _|_____________ __________|


Nov 12 '05 #8
Vladimir wrote:
Row Source is *NOT* a property of a Field. It's a property
of the ComboBox on the Form in Access.
Then how can I get those sort of properties?


I'm not sure you can with ADO. If you use Access COM, you might
be able to, but it may require the form be open (the Access COM
includes a Forms collection, which would contain the Form in
question, but I'm not sure you can access it unless the Form is
opened).
Are you saying you get "Above" in that case and "1" if you issue
an SQL statement through VC++? That's.... impossible. Something
else is going on. Are you sure the Query Designer isn't linking
in a table or doing some sort of lookup?


It is possible. You can create your own table in Access with one
field having lookup with following properties:

Display control = Combo Box
Row ource type = Value list
Row source = 1;"qwe";2;"asd" ;3;"zxc"
Bound column = 1
Column count = 2
Column heads = No
Column widths = 0cm;4cm
List rows = 8
List width = 4cm
Limit to list = Yes


Yes, this is exactly what I was talking about. The Access table
has a control defined in it. I'm fairly certain you can't access
this via ADO, but you might via Access COM.
Then fill table with data and enter MANUALLY in Query Designer
(View / SQL mode) this text: SELECT <field> FROM <table> - and
you will get strings.


Yes, I see what you mean, now. I'm leaving for the day and might
not be back until Monday, but if you are still having trouble then,
I'll see if I can provide some areas to explore.

--
|_ CJSonnack <Ch***@Sonnack. com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ _______________ ____| Call: 1-800-DEV-NULL |
|______________ _______________ _______________ _|_____________ __________|
Nov 12 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3204
by: Irena | last post by:
Hi all again, Maybe, I'd better try to do this: How can it programmatically get/return the "Row source" or Rowsource property of a generic Table in a generic Access 2K database??? I found an example in VB: me!combobox.RowSource
0
1524
by: Irena | last post by:
Hi all there, Form time to time, I go back to this project of mine that drives me nuts, now. Sometimes ago, I have been suggested to use DAO insted of ADO for getting the "ROWSOURCE" property of an Access table. So it should have worked like this: ....fldName.Properties("RowSource").
8
6159
by: bbdata | last post by:
ok i have a problem here and not much time to play round. have a form bound to a table. one of the combos is bound to a field Agents. i have active and retired agents. thing is, i want to be able to retrieve all agents from the table, but to see only active in dropdown list of the combo, to asure accurate data entry. if i filter the agents table for a rowsource to get back only active in the dropdown, i cant retreive names of the rest when...
13
4180
by: nyt | last post by:
I have a problem of number and text field. I got the database file(mdb) that contains many combo boxes used and its list values are created by "value list" For eg field Field name= 'furniture' , data type='Number' ,Display Control='Combo Box', RowSource Type = 'Value List' and Row Source = ' 0;"chair";1;"Table";2;"Bed" ' Therefore, in data sheet view of table, if we select (1 : Table ) ,
3
2438
by: Richard Hollenbeck | last post by:
I have a column in a table that currently only has one record. That column is set to combo box. I want the user to be able to lookup values from the column itself--the very same column--rather than a long list of values in the rowsource. Then, if the value doesn't exist, the user could type it in, and the next time that value is needed again it will be there in the list without having to manually add that value to the rowsource. Is this...
3
2120
by: u473 | last post by:
How do I call a reusable report with a modifiable Rowsource property and or code ? Like in the following case where the table name will change any following day ? I am using Access 2003. Private Sub Top25_Click() Dim strSQL As String strTblName = "tblNew_" & Format(Date, "ddmmmyyyy") strSQL = "SELECT TOP 25 tblOld.Fname, tblOld.Lname INTO " &
4
8478
by: madereal | last post by:
howdy scriptors… here’s my question: Project Background: I’m creating a database that will hold questionnaire data. Situation: I would like to set up a combobox with a changing rowsource property on a continuous form. I have created a query for the record source so that the text value of the rowsource property is included as a separate field for each record. I have call this field: and an example of the text is: (1;Yes;2;No). ...
8
23816
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Form is: Forms!FormName..RowSource = "TableOrQueryName"
11
7457
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Master Report is: Me.RowSource = "TableOrQueryName"
0
10040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.