SubForm Field Name event (1 Viewer)

kirkm

Registered User.
Local time
Today, 13:32
Joined
Oct 30, 2008
Messages
1,257
On my datasheet subform, when the field name is clicked, it moved to Record 1 of xx and the Current Event fires.
Is this normal behaviour? Is there any way to prevent it moving to Record 1 ?
 

Micron

AWF VIP
Local time
Yesterday, 21:32
Joined
Oct 20, 2018
Messages
3,478
You must have some code behind the form? When I click on a datasheet column label, all it does is highlight the entire field. I suspect you have code that is causing a requery of the form, thus the reason for why it moves to the first record. The only way you'd know that the current event fires is if you have code for it, and no you cannot cancel the current event. You can prevent moving to record #1 by not requerying. I'm assuming that by "field name is clicked" you mean the field header at the top of the subform.
 

kirkm

Registered User.
Local time
Today, 13:32
Joined
Oct 30, 2008
Messages
1,257
Yes, the field headers. I wondered about code behind it, so remmed it all out and it still did it. However there is code behind the main form.
I'll make a mockup in a new db and see what happens. Nice to know it shouldn't happen.
 

kirkm

Registered User.
Local time
Today, 13:32
Joined
Oct 30, 2008
Messages
1,257
Micron, would you open Form1 in the attached, click some record other than 1 then click on a field header.
Does it stay on the the record you clicked, or move to Record 1 ?
Thanks.
 

Attachments

  • test.accdb
    824 KB · Views: 82

Minty

AWF VIP
Local time
Today, 02:32
Joined
Jul 26, 2013
Messages
10,371
That's because you are effectively selecting all the records by doing that, so by default, it says you are on the first record.

If you changed from datasheet view and made a continuous form that looked like a datasheet, you can make the field header labels do the sorting etc you require without losing track of the record you are on, although it does take more work
 

Micron

AWF VIP
Local time
Yesterday, 21:32
Joined
Oct 20, 2018
Messages
3,478
Minty replied before I had a chance to look but I did repeat the exercise on a test db of my own and see that it does exactly that. Is this behaviour something that you really need to worry about? Or should the answer be like that of the doctor, when the patient says "Doc, it hurts when I do this" to which Doc replied "Well then don't do that". ;)
OK, all joking aside, you are saying that the record counter indicates 1 of x or that if you are on say, record 100 it jumps back to putting 1 at the top of the view?

My company just arrived so I have to drop out for a while.
 

kirkm

Registered User.
Local time
Today, 13:32
Joined
Oct 30, 2008
Messages
1,257
If that's how it is so be it. Although a good solution, I discarded continuous Form once realising you could no longer size/move the column widths.
Yes, Micron it's the latter. Selecting the whole column then control-F to search. You could say it makes sense as the search is from Col 1 but I'd have preferred to not do that (and remain where you were if the search found nothing) . Also not run the Current event, which it does, but figured a way around that.
Thanks for the feedback.
 

Micron

AWF VIP
Local time
Yesterday, 21:32
Joined
Oct 20, 2018
Messages
3,478
I may not have expressed what I meant very well because I when I click on the top of a datasheet header, it does change the record counter to say "1 of x" but the records don't move. You seem to be saying they do.

Maybe what you want to do then is take a look at working with a recordset clone. You can search it for a record in a recordset clone and do something if found or nothing if not found, so you don't lose your place in the form record display. Even if you do move off the current record, you can return to your place if you have created a bookmark first.
 

kirkm

Registered User.
Local time
Today, 13:32
Joined
Oct 30, 2008
Messages
1,257
You're right! I apologise - display doesn't move unless search succeeds, so it actually is perfect. Guess the record counter threw me.
Thanks for recordset clone idea. I'll remember that. This is all coming togther well now, more is being done the 'right' way rather than my way!
 

Micron

AWF VIP
Local time
Yesterday, 21:32
Joined
Oct 20, 2018
Messages
3,478
Well, if we helped at all with this issue, then that is great!
Good luck with your db!
 

kirkm

Registered User.
Local time
Today, 13:32
Joined
Oct 30, 2008
Messages
1,257
Many thanks Micron I don't do enough of this and often forget essentials. (And I just implemented something using the recordset clone you suggested!)
 

Users who are viewing this thread

Top Bottom