Screen.Previous Control - Detect

gray

Registered User.
Local time
Today, 10:55
Joined
Mar 19, 2007
Messages
578
Hi All

Access 2002/2007
WunXPPro

I have an edit button which uses Screen.PreviousControl to determine what needs to be edited.

My code fails when screen.PreviousControl does not exist... Anyone know how to test for the existence of it please?

So far I've tried:

If Screen.PreviousControl Is Nothing Then
MsgBox "No Field Selected - Edit Request Ignored"

If isNull(Screen.PreviousControl) Then
MsgBox "No Field Selected - Edit Request Ignored"

even...

If isEmpty(Screen.PreviousControl) Then
MsgBox "No Field Selected - Edit Request Ignored"

All fail with a 2467 error?

Thanks
 
If all else fails, catch the error and test for 2467.
 
What, exactly, are you doing to make the controls in your form non-editable to begin with?

Linq ;0>
 
Dim PrevCtl As Control
Const ERR_OBJNOTEXIST = 2467
Const ERR_OBJNOTSET = 91
Set PrevCtl = Screen.PreviousControl
your code etc
Exit_Command95_Click:
Exit Sub
Err_Command95_Click:
If (Err = ERR_OBJNOTEXIST) Or (Err = ERR_OBJNOTSET) Then
Resume Next
 
Hi

Thanks for the replies chaps... must admit I've always been reluctant to test for error-codes... I've been caught out in the past when manufacturers have changed them... but I'll go with it today... thanks.

In answer to missinglinq's question... I don't think they are becoming uneditable as such... I have subforms and I think the error manifested itself when a returning from a subform to a button on the main... the first job in the button's event was to test previous control... based on that I wander off and take an action... sometimes it just seems to lose previous control details.... Actually, I forget stuff all the time myself! :)

Rgds
 
... I have subforms and I think the error manifested itself when a returning from a subform to a button on the main... the first job in the button's event was to test previous control...
Therein lies your problem! You're testing for the data or value, if you will, for the Previous Control, thinking that the 'previous control' is the textbox on the SubForm that the cursor was on before clicking your button on the Main Form! The problem is, that to the Main Form, the Previous Control was the SubForm Control itself, not the Control on the SubForm! The Main Form only knows about the SubForm Control! It knows nothing about anything, such as a textbox, that lies there within!

For your code to work, as written, the Edit button would have to reside on the SubForm itself, not on the Main Form!

Linq ;0)>
 
Hiya

Is there no way to test for the existence or even 'empty' state of previous control though (other than using the error code trap)? I tried Isnull, Is Empty, Is Nothing?

Actually I found a great tip for subform controls.... for anyone else out there grappling with this....

Me.Form.Controls(Screen.PreviousControl.Name).Form.ActiveControl

will, from the Main form, allow you reference to the control most recently used inside the subform.

Alas... this is where my plan falls over.. I test to see if previous control is a subform and if so then grab its active control... from time to time, however, previous control is lost somewhere in the space/time continuum :)

rgds
 
If IsNull(Screen.PreviousControl) Then

will, indeed, tell you if the Previous Control is empty, i.e. has no data entered in it. But not if the Previous Control is a SubForm Control! This type of Control has no Value Property to be tested!
 

Users who are viewing this thread

Back
Top Bottom