Screen.ActiveControl - error 91 - object variable or with block not set

S

Stapes

Hi

I am trying to run the following code & am getting the error message
shown above. The code is triggered by entering a value in any field on
my screen.

Private Function UpdateTariff()
On Error GoTo Err_UpdateTariff
Dim ctl As Control
Dim strControlName As String
ctl = Screen.ActiveControl
strControlName = ctl.Name
MsgBox strControlName
Exit_UpdateTariff:
Exit Function
Err_UpdateTariff:
MsgBox Err.Number & " " & Err.Description
Resume Exit_UpdateTariff
End Function

Any idea why it is not working?

Stapes
 
S

Stefan Hoffmann

hi Stapes,
I am trying to run the following code & am getting the error message
shown above. The code is triggered by entering a value in any field on
my screen.

Private Function UpdateTariff()
On Error GoTo Err_UpdateTariff
Dim ctl As Control
Dim strControlName As String
ctl = Screen.ActiveControl
Try

If Not ctl Is Nothing Then
strControlName = ctl.Name
MsgBox strControlName
End If



mfG
--> stefan <--
 
S

Stapes

hi Stapes,



Try

If Not ctl Is Nothing Then> strControlName = ctl.Name

End If

mfG
--> stefan <--

Hi Stefan
It does not get that far. The error occurs on the command:

ctl = Screen.ActiveControl

Stapes
 
S

Stefan Hoffmann

hi Stapes,
It does not get that far. The error occurs on the command:

ctl = Screen.ActiveControl
Then put the If before that line. The error is normally caused when
Screen.ActiveControl does not point to any control.


mfG
--> stefan <--
 
S

Stapes

hi Stapes,



Then put the If before that line. The error is normally caused when
Screen.ActiveControl does not point to any control.

mfG
--> stefan <--

No - that doesn't make any sense. If the field ctl has not been primed
- then it won't have anything there.
 
S

Stapes

No - that doesn't make any sense. If the field ctl has not been primed
- then it won't have anything there.

Hi

I found my error - I omitted to put 'Set' before ctl =
Screen.ActiveControl

Stapes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top