Save Current Control State

Bud

New member
Local time
Today, 20:59
Joined
Oct 23, 2004
Messages
8
Hi all,

Maybe I'm being too bold here on my first mission :) but can anyone explain to me "how to save the current control state"? I'm updating my form (displaying the number of words in a memo field) on the On_Current() event. But because I shift the focus to this field I keep on ending up with the focus to there. But I would like the 'old' control focus restored. How do I solve this litlle problem?

Is there something like a "save control state" command?

Thanks for your time reading (and even more for responding to) this message!
Bud.
 
Bud,

I hope I'm following... After the code in your form's On Current event fires, you want to move focus back to particular control.

To do so, use the DoCmd.GotoControl method, tagging a line of code like the following to the end of the Current procedure...

DoCmd.GoToControl "ControlName"

Regards,
Tim
 
Tim,

Thank you for responding to my question!

The thing is, that normally when you scroll your records with let's say the mouse wheel, the control stays in the same field (you see the cursor blinking). If I want to update a label on the form (# of words in a certain memo field) I use a small routine theat does the trick for me:

Private Sub Form_Current()

Dim First$ 'Variable to hold memo string
Dim arr As Variant 'Variable to hold string when split (array)
Dim n% 'Variable to hold number of words (size of Array)

Me.fldVraag.SetFocus
First$ = fldVraag.Text 'Get text from Memo field
First$ = Replace(First$, " ", " ", 1) 'Remove double spaces
arr = Split(First$, " ") 'Split up into individual words
n% = UBound(arr) + 1 'Find size of Array

Me.fldWoorden.SetFocus 'Set focus to text field to display number of words
Me.fldWoorden.Text = n% 'Set the value of the text field
Me.fldWoorden.Enabled = True
Me.fldWoorden.Visible = True

Me.fldVraagID.SetFocus

End Sub

It's the last part ... Me.fldVraagID.SetFocus ... this sets the focus right back to the first field in the form. So everytime I scroll through the records the focus goes back to field 1. BUT, that's not what I want. What I want is to first store the current control, do the tricky and return to the former (correct)
control.

So that the cursor stays in the same field after changing a record. I would imagine there was a command like:


X = Me.ActiveControl.SaveState

and

Me.ActiveControl.SaveState = X

Well I hope you get it now. Any ideas maybe?

Thanks again Tim,
Bud.
 
You don't need to set focus to the field at all. Just don't use the .Text property of it. In other words,

First$ = fldVraag

and

Me.fldWoorden = n%

Focus will stay where it was.
 
Very nice solution! Thank you very much Paul, but there must be something I'm missing here. WHY do I not need the .Text property to set the new value of the field (sorry but I'm not a diehard Access programmer).

Thanks again!
Bud.
 
You can use the .Value property to do what you're doing, and it doesn't need focus. It's the default, which is why you don't need to specify it. You only need the .Text property when you're working in a control before it's been updated.
 

Users who are viewing this thread

Back
Top Bottom