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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I determine what field I am 2

Status
Not open for further replies.

MikeBronner

Programmer
May 9, 2001
756
US
How do I determine what field I am currently editing in an ADO recordset?

I'm looking for something like

if (adoSet.Fields.Item.Name = "Response") Then

where Response is the name of the field I am looking for. However, when I tried the above, it requires me to add the index number of the item.

Thanks!
 
Try this . . .

if adoSet.Fields(1).Name = "Response" then

or, more generically,

dim objField as adodb.field

for each objField in adoSet.fields
if objField.Name = "Response" then
'** Do something
Exit loop
end if
next objField
- Jeff Marler B-)
 
Actually that wouldn't fullfil what I'm trying to do. I probably didn't explain enough (sorry :p).

Here's what I'm trying to do: When I hit the <Enter> key a sub procedure will be executed using the KeyPress event. there I want to check if the current field I'm editing is in fact the field named &quot;Response&quot;.
 
In other words, I would like a statement which returns the index number or name of the current field I'm in. Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Open your mind, and the rest will follow.&quot;
 
&quot;Open your mind, and the rest will follow.&quot;

Follow your own advice - and Jeff Marler's. In tandem, the soloution is already there ... '** Do Something is where you decide on the 'index'

Good job Jeff!


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Michael, Jeff, please bear with me :):

for each objField in adoSet.fields
if objField.Name = &quot;Response&quot; then
'** Do something
Exit loop
end if
next objField

As far as I understand Jeff's code, this will loop through each field, looking for the one called &quot;Response&quot;. Then it will find this field, regardless of which field the user is editing at the moment, is that not correct? This means that regardless if I'm in field 4 or field 9, it will always find the field labeled &quot;Response&quot; each time the procedure is executed.

Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Open your mind, and the rest will follow.&quot;
 
When the user is editing the field, do you have access to the specific field object that they are editing? You can check for the name off of that . . . How are they editing the field if you do not know what field it is? - Jeff Marler B-)
 
The control source for the field may be what you are looking for. It would be 'something like ... ':

ActiveControl.ControlSource

but may vary depending on which version you are using. Of course, this assumes that you are using BOUND Controls


Sorry for the confusion. I just blew past the (important Part of) the question.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Jumping right in...
If I understand you correctly you want to return the field index for the current field as in:
Code:
oRs.Fields(x)...
where 'x' would be your index.

As far as I know there is no way of returning the index variable directly from the field object. If you truly need an integer index you would have to manually code a counter.

Code:
dim objField as adodb.field
dim i as Integer

i = 0
for each objField in adoSet.fields
    i = i + 1
    if objField.Name = &quot;Response&quot; then
        '** Do something
        Exit loop
    end if
next objField

I advise against using this code however as the index only shows the order you have specified in your query, and is subject to change whenever you modify that. A better solution is to use the Name property of the field to do the matching you need.

Good Luck!
-Mats Hulten
 
Michael, Jeff:

Thanks for taking your time with me here.
Michael, you are right as to what I want. The user is editing the fields by accessing them via textboxes in a bound control. This control is contained in a datarepeater, so that each record is displayed.
As the user goes from field to field, either entering new values, or changing existing ones, I would like to check which field he/she is currently in, in order to determine when to jump to the next record, and other similar maneuvers.

Does this open any new possibilities? Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Open your mind, and the rest will follow.&quot;
 
Michael,

It may get down to the version(s) of stuff. I 'rember' ther was a &quot;property&quot; of some of the data bound controls which determined the action when the data repeater reached the last field of a record (go back to first field | go to next record) - although those are not the names.

I do not normally use the datarepeater, prefering unbound controls for VB. There is some additional design/programming/setup stuff to contend with, but I feel like there is some more positive control over what is being done to the db tables/fields. My (hazy) memory suggests that some versions of datacontrols have a property on the fiels (or Control?) on how to treat the change of focus on the &quot;last&quot; field - move to next record or just to first field.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Well,
I turned to a last resort: I did the operation in the custom control level, using the KeyPress Event in the necessary controls.

I wanted to avoid doing this, to give the control more freedom, but I guess there isn't an easy solution.

Thanks for all your help guys! If you do happen to find a solition, please do post it here. :)

PS: Kudos to all you pros helping us out here! It's greatly appreciated! B-) Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Open your mind, and the rest will follow.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top