Thread View: be.comp.programming
6 messages
6 total messages
Started by Vladimir
Mon, 15 Sep 2003 19:33
HOWTO: use RowSource property of a field in MS Access table
Author: Vladimir
Date: Mon, 15 Sep 2003 19:33
Date: Mon, 15 Sep 2003 19:33
21 lines
2349 bytes
2349 bytes
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.Recordset");
tmp = "select field from table"; // query
pRs->Open((_bstr_t)tmp, _variant_t((IDispatch*)pGWMConn, true),
adOpenForwardOnly, 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.
Re: HOWTO: use RowSource property of a field in MS Access table
Author: Programmer Dude
Date: Mon, 15 Sep 2003 20:05
Date: Mon, 15 Sep 2003 20:05
28 lines
2371 bytes
2371 bytes
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 <Chris@Sonnack.com> _____________| How's my programming? | |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL | |_____________________________________________|_______________________|
Re: HOWTO: use RowSource property of a field in MS Access table
Author: Vladimir
Date: Tue, 16 Sep 2003 06:10
Date: Tue, 16 Sep 2003 06:10
49 lines
3627 bytes
3627 bytes
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 <cjsonnack@mmm.com> ����� � ���������:3F661B99.F254B2B5@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 <Chris@Sonnack.com> _____________| How's my programming? | > |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL | > |_____________________________________________|_______________________|
Re: HOWTO: use RowSource property of a field in MS Access table
Author: Programmer Dude
Date: Tue, 16 Sep 2003 20:42
Date: Tue, 16 Sep 2003 20:42
40 lines
2867 bytes
2867 bytes
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 <Chris@Sonnack.com> _____________| How's my programming? | |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL | |_____________________________________________|_______________________|
Re: HOWTO: use RowSource property of a field in MS Access table
Author: Vladimir
Date: Wed, 17 Sep 2003 19:40
Date: Wed, 17 Sep 2003 19:40
50 lines
3094 bytes
3094 bytes
Hello, Programmer Dude <Chris@Sonnack.com> ����� � ���������:3F6775C4.B68635B6@Sonnack.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.
Re: HOWTO: use RowSource property of a field in MS Access table
Author: Programmer Dude
Date: Thu, 18 Sep 2003 20:18
Date: Thu, 18 Sep 2003 20:18
48 lines
3105 bytes
3105 bytes
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 <Chris@Sonnack.com> _____________| How's my programming? | |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL | |_____________________________________________|_______________________|
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads