Setting SelLength = 0 not working? (1 Viewer)

KeithWilliams

Registered User
Joined
Feb 9, 2004
Messages
137
Hi,

I have the following code in my form's open event:
Me!Calc_Actual.SetFocus
Me!Calc_Actual.SelLength = 0

This code has no effect. I want to avoid the field that initially gets focus from being highlighted (but it needs to be enabled and locked). The field already gets focus by default, I just coded the SetFocus because the MS Help says the field must have focus in order to use SelLength.

I wonder if the Open event is too early for this to work. Can I "post" an action to the form?

I also tried putting the code in the form's Load event but that doesn't seem to fire (I put a debug stop in the event and it does not stop there). I can't explain this. I've also tried setting Behaviour Entering Field = Go To Start Of Field (instead of Select Entire Field) in the Tools>Options of Access, but this has no effect.

Thanks,
Keith.
 

Mile-O

Back once again...
Joined
Dec 10, 2002
Messages
11,312
If the textbox Calc_Actual is bound to a field then it's fruitless putting the code in the Form_Open as this event is triggered before the underlying recordset is loaded into the form.

Put it in the Form_Load event.


Also, are you sure you want the SelLength and not the SelStart property?


And use Me. and not Me!
 

KeithWilliams

Registered User
Joined
Feb 9, 2004
Messages
137
Hi Mile-O-Phile

I've tried the Form_Load event but it doesn't fire. I've checked and it appears that Load doesn't fire on any of my forms where I dynamically assign the recordset, but does on those simple forms where I don't mess with the recordset.

Is there another place I can put the script where it will fire after the Open?

I've also tried other combinations with SelLength, SelStart, Me. and Me! to no avail.

Thanks,
Keith.
 

Mile-O

Back once again...
Joined
Dec 10, 2002
Messages
11,312
KeithWilliams said:
Is there another place I can put the script where it will fire after the Open?
What exactly is it that you are wanting to do? :confused:


Me. and Me! to no avail.
That was just an aside.
 

KeithWilliams

Registered User
Joined
Feb 9, 2004
Messages
137
Hi,

The default behaviour I am getting is that the form opens with the first field already having focus and its value highlighted. The first field is the calc_actual field in the first row - the form is set to Continuous Forms.

I want to suppress that behaviour so that the field still has focus, but with nothing highlighted.

(I'm thinking perhaps I need to set all fields to Locked=Yes, Enabled = No then change them back after opening the form, but I wouldn't know what event to use to change them back, since Load isn't firing in the form).

Thanks,
Keith.
 

Mile-O

Back once again...
Joined
Dec 10, 2002
Messages
11,312
I just tried what you described in the Form_Load event of a set of continuous forms with this code:

Code:
    Me.txtExample.SetFocus
    Me.txtExample.SelStart = 0

It worked fine.
 

KeithWilliams

Registered User
Joined
Feb 9, 2004
Messages
137
Hi,

That's what I figured, but the Load event doesn't fire on my form. If I code a Load event comprising just a MsgBox "hello", the message doesn't appear. I did try putting the code you used in the Load event, but it doesn't work. That's when I found that the load event wasn't firing at all.

As I suggested earlier, i think this is because I am dynamically creating my recordset.

Thanks,
Keith.
 

Mile-O

Back once again...
Joined
Dec 10, 2002
Messages
11,312
KeithWilliams said:
As I suggested earlier, i think this is because I am dynamically creating my recordset.
I missed that earlier. Yes, that'll cause it not to trigger. When you change the recordset, insert:

Code:
Call Form_Load
as the final line.
 

KeithWilliams

Registered User
Joined
Feb 9, 2004
Messages
137
Hi,

I tried adding that and it made no difference. I think when I call form_load from within form_open, it is still too "early" to affect the display of the form. Effectively it is just as though I am calling another sub from within the Open event.

Thanks,
Keith.
 

Mile-O

Back once again...
Joined
Dec 10, 2002
Messages
11,312
You are building and assigning a recordset in the Form_Open event? Why not just make a premade query?

Still having problems, then upload an example.
 

KeithWilliams

Registered User
Joined
Feb 9, 2004
Messages
137
Hi,

Yup, I've done that in several forms in the application. Its to allow me to set query parameters at runtime (based on selections in other forms) without the user being prompted to enter the parameter values.

Works really well, except that I now find that the Load event doesn't happen!

Thanks, but its way too big to upload (10MB zipped). It has too many dependencies to easily break down. Guess my users will have to live with it the way it is!

Thanks,
Keith.
 

le888

Registered User
Joined
Dec 10, 2003
Messages
344
Try this :

Code:
Private Sub txtExample_Enter()

Me.txtExample.setfocus
Me.txtExample.SelStart = 0

End Sub
Put it in the Enter event.

Le
 

le888

Registered User
Joined
Dec 10, 2003
Messages
344
KeithWilliams said:
Hi Le,

Tried that, but it had no effect!

Thanks,
Keith.
See my sample, Open the "frmFirst" which highlight the whold word and "frmSecond" which doesn't highlight the whold word.

Le
 

Attachments

Pat Hartman

Super Moderator
Staff member
Joined
Feb 19, 2002
Messages
28,528
The Current event is more appropriate for this. It fires every time the form moves to a new record. I am assuming that you want this behaviour for every record, not just the first one.
 

KeithWilliams

Registered User
Joined
Feb 9, 2004
Messages
137
Hi,

Thanks for the suggestions, I tried Le's sample, and that works fine, but putting the same code into my form doesn't work - the Enter event for the field and the Current event for the form both fire before the form appears, but the field value is initially highlighted in every case.

Thanks,
Keith.
 

missinglinq

AWF VIP
Joined
Jun 20, 2003
Messages
6,329
Maybe I'm over-simplifying the problem, but if you want this proceedure to occur when the control receives focus, why not place it in the GotFocus Event for the control?

Just a thought.

The Missinglinq
 

KeithWilliams

Registered User
Joined
Feb 9, 2004
Messages
137
Hi,

Tried that in the GotFocus and no joy.

I've finally bitten the bullet and created a minimal sample database with one form that illustrates the problem. If you open the database and then open form performance, you should see the problem - the first Actual value is highlighted. I've included the SelStart = 0 in various places, and SelLength for good measure.

(The logic is complex but all there for good reason - it may not make much sense in isolation with much of the code and other objects removed).

I'd really appreciate if someone can tell me how to get past this.

Thanks,
Keith.
 

Attachments

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom