A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Why don't I get error 2164 'Can't disable a control while it has thefocus'?



 
 
Thread Tools Display Modes
  #1  
Old February 23rd, 2009, 11:03 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 15
Default Why don't I get error 2164 'Can't disable a control while it has thefocus'?

I have a form with various bound controls including VitalStatus (is
this person alive, dead or of unknown status) and DateOfDeath. The
latter control should only be enabled when the VitalStatus is
conDead. The code I have to do this is:

Private Sub VitalStatus_AfterUpdate()
On Error GoTo Err_VitalStatus_AfterUpdate

'Constant based on tlkpVitalStatus
Const conDead As Byte = 2

If Me!VitalStatus = conDead Then
If Not Me!DateOfDeath.Enabled Then
Me!DateOfDeath.Enabled = True
End If
If Not Me!MainAgeAtDeath.Enabled Then
Me!MainAgeAtDeath.Enabled = True
End If
Else 'ie alive or unknown
If Me!DateOfDeath.Enabled Then
Me!DateOfDeath = Null
Me!DateOfDeath.Enabled = False
End If
If Me!MainAgeAtDeath.Enabled Then
Me!MainAgeAtDeath.Enabled = False
End If
End If

Exit_VitalStatus_AfterUpdate:
Exit Sub

Err_VitalStatus_AfterUpdate:
Call LogError(Err.Number, Err.Description, "frmMain:
VitalStatus_AfterUpdate()")
Resume Exit_VitalStatus_AfterUpdate
End Sub

The same code exists in the Form_Current event except for the
assignment statement (Me!DateOfDeath = Null).

What puzzles me is that I can navigate through the records in a form,
in which most entries for VitalStatus are for dead patients
(VitalStatus = conDead), with the focus in the DateOfDeath field.
When I enter a record in which VitalStatus is not conDead then the
focus is shifted to the first field on the form and DateOfDeath is
disabled. I was expecting instead to get Error 2164 'Can't disable a
control while it has the focus' based on the Form_Current event. Why
don't I?
  #2  
Old February 23rd, 2009, 11:16 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Why don't I get error 2164 'Can't disable a control while it has the focus'?

wrote in message
...
I have a form with various bound controls including VitalStatus (is
this person alive, dead or of unknown status) and DateOfDeath. The
latter control should only be enabled when the VitalStatus is
conDead. The code I have to do this is:

Private Sub VitalStatus_AfterUpdate()
On Error GoTo Err_VitalStatus_AfterUpdate

'Constant based on tlkpVitalStatus
Const conDead As Byte = 2

If Me!VitalStatus = conDead Then
If Not Me!DateOfDeath.Enabled Then
Me!DateOfDeath.Enabled = True
End If
If Not Me!MainAgeAtDeath.Enabled Then
Me!MainAgeAtDeath.Enabled = True
End If
Else 'ie alive or unknown
If Me!DateOfDeath.Enabled Then
Me!DateOfDeath = Null
Me!DateOfDeath.Enabled = False
End If
If Me!MainAgeAtDeath.Enabled Then
Me!MainAgeAtDeath.Enabled = False
End If
End If

Exit_VitalStatus_AfterUpdate:
Exit Sub

Err_VitalStatus_AfterUpdate:
Call LogError(Err.Number, Err.Description, "frmMain:
VitalStatus_AfterUpdate()")
Resume Exit_VitalStatus_AfterUpdate
End Sub

The same code exists in the Form_Current event except for the
assignment statement (Me!DateOfDeath = Null).

What puzzles me is that I can navigate through the records in a form,
in which most entries for VitalStatus are for dead patients
(VitalStatus = conDead), with the focus in the DateOfDeath field.
When I enter a record in which VitalStatus is not conDead then the
focus is shifted to the first field on the form and DateOfDeath is
disabled. I was expecting instead to get Error 2164 'Can't disable a
control while it has the focus' based on the Form_Current event. Why
don't I?



Interesting; I'd have expected the same as you. But so far as I can tell,
the control isn't given the focus until after the Current event.
Interrogating Me.ActiveControl or Screen.ActiveControl in the Current event
raised error 2474, "The expression you entered requires the control to be in
the active window."

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

  #3  
Old February 23rd, 2009, 11:34 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 15
Default Why don't I get error 2164 'Can't disable a control while it hasthe focus'?

On Feb 24, 8:16*am, "Dirk Goldgar"
wrote:
wrote in message

...





I have a form with various bound controls including VitalStatus (is
this person alive, dead or of unknown status) and DateOfDeath. *The
latter control should only be enabled when the VitalStatus is
conDead. *The code I have to do this is:


Private Sub VitalStatus_AfterUpdate()
* *On Error GoTo Err_VitalStatus_AfterUpdate


* *'Constant based on tlkpVitalStatus
* *Const conDead As Byte = 2


* *If Me!VitalStatus = conDead Then
* * * *If Not Me!DateOfDeath.Enabled Then
* * * * * *Me!DateOfDeath.Enabled = True
* * * *End If
* * * *If Not Me!MainAgeAtDeath.Enabled Then
* * * * * *Me!MainAgeAtDeath.Enabled = True
* * * *End If
* *Else 'ie alive or unknown
* * * *If Me!DateOfDeath.Enabled Then
* * * * * *Me!DateOfDeath = Null
* * * * * *Me!DateOfDeath.Enabled = False
* * * *End If
* * * *If Me!MainAgeAtDeath.Enabled Then
* * * * * *Me!MainAgeAtDeath.Enabled = False
* * * *End If
* *End If


Exit_VitalStatus_AfterUpdate:
* *Exit Sub


Err_VitalStatus_AfterUpdate:
* *Call LogError(Err.Number, Err.Description, "frmMain:
VitalStatus_AfterUpdate()")
* *Resume Exit_VitalStatus_AfterUpdate
End Sub


The same code exists in the Form_Current event except for the
assignment statement (Me!DateOfDeath = Null).


What puzzles me is that I can navigate through the records in a form,
in which most entries for VitalStatus are for dead patients
(VitalStatus = conDead), with the focus in the DateOfDeath field.
When I enter a record in which VitalStatus is not conDead then the
focus is shifted to the first field on the form and DateOfDeath is
disabled. *I was expecting instead to get Error 2164 'Can't disable a
control while it has the focus' based on the Form_Current event. *Why
don't I?


Interesting; *I'd have expected the same as you. *But so far as I can tell,
the control isn't given the focus until after the Current event.
Interrogating Me.ActiveControl or Screen.ActiveControl in the Current event
raised error 2474, "The expression you entered requires the control to be in
the active window."

--
Dirk Goldgar, MS Access MVPwww.datagnostics.com

(please reply to the newsgroup)- Hide quoted text -

- Show quoted text -


Hello Dirk,

Many thanks for replying. I have little experience with the Access
event model and I'm afraid your answer is unclear to me. Could you
dumb it down?

Kind regards,
John
  #4  
Old February 24th, 2009, 02:48 AM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Why don't I get error 2164 'Can't disable a control while it has the focus'?

wrote in message
...
On Feb 24, 8:16 am, "Dirk Goldgar"
wrote:

Interesting; I'd have expected the same as you. But so far as I can tell,
the control isn't given the focus until after the Current event.
Interrogating Me.ActiveControl or Screen.ActiveControl in the Current
event
raised error 2474, "The expression you entered requires the control to be
in
the active window."


Hello Dirk,

Many thanks for replying. I have little experience with the Access event
model and I'm afraid your answer is unclear to me. Could you dumb it
down?



Hi, John -

You've discovered something that surprised me, so my conclusions should be
taken as conjectures, not gospel. But it appears that, during the form's
Current event, *no* control has the focus. Yet, immediately after that
event, focus is sent to the control that had the focus previously, if
possible. If that is not possible, or if the form was just opened, it looks
like the focus is set to the first control in the tab order that is
currently capable of receiving the focus.

Therefore, in the Current event, you can disable the control that *formerly*
had the focus, because that control doesn't have the focus *now*, in the
event procedure. If you didn't disable it, it would get the focus *again*,
but if you disable it, the first "available" control will get the focus.

One of the ways I tested this was to put code in a form's Current event to
print the name of the current active control on the form, which can be
retrieved from the form's ActiveControl property. I wrote an event
procedure like this:

Private Sub Form_Current()

Debug.Print Me.ActiveControl.Name

End Sub

But when I ran the form with that code, I always got an error, as I
mentioned in my previous post. From that and some other tests I conclude
that there *is* no ActiveControl -- no control with the focus -- when the
form's Current event is raised.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

  #5  
Old February 24th, 2009, 04:12 AM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 15
Default Why don't I get error 2164 'Can't disable a control while it hasthe focus'?

On Feb 24, 11:48*am, "Dirk Goldgar"
wrote:
wrote in message

...





On Feb 24, 8:16 am, "Dirk Goldgar"
wrote:


Interesting; I'd have expected the same as you. But so far as I can tell,
the control isn't given the focus until after the Current event.
Interrogating Me.ActiveControl or Screen.ActiveControl in the Current
event
raised error 2474, "The expression you entered requires the control to be
in
the active window."


Hello Dirk,


Many thanks for replying. *I have little experience with the Access event
model and I'm afraid your answer is unclear to me. *Could you dumb it
down?


Hi, John -

You've discovered something that surprised me, so my conclusions should be
taken as conjectures, not gospel. *But it appears that, during the form's
Current event, *no* control has the focus. *Yet, immediately after that
event, focus is sent to the control that had the focus previously, if
possible. *If that is not possible, or if the form was just opened, it looks
like the focus is set to the first control in the tab order that is
currently capable of receiving the focus.

Therefore, in the Current event, you can disable the control that *formerly*
had the focus, because that control doesn't have the focus *now*, in the
event procedure. *If you didn't disable it, it would get the focus *again*,
but if you disable it, the first "available" control will get the focus.

One of the ways I tested this was to put code in a form's Current event to
print the name of the current active control on the form, which can be
retrieved from the form's ActiveControl property. *I wrote an event
procedure like this:

* * Private Sub Form_Current()

* * * * Debug.Print Me.ActiveControl.Name

* * End Sub

But when I ran the form with that code, I always got an error, as I
mentioned in my previous post. *From that and some other tests I conclude
that there *is* no ActiveControl -- no control with the focus -- when the
form's Current event is raised.

--
Dirk Goldgar, MS Access MVPwww.datagnostics.com

(please reply to the newsgroup)- Hide quoted text -

- Show quoted text -


Thanks for the explanation, Dirk.

I'm happy to have piqued your interest!

Kind regards,
John
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:46 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.