SetFocus

  • Thread starter Thread starter Fly Girl
  • Start date Start date
F

Fly Girl

OK, I'm really feeling like an idiot here and I need
someone to either tell me to get a grip or explain why
this won't work:

In the MyControl_AfterUpdate event of a control on a form
I want to evaluate criteria and if it's not met, then send
the user a message and dump them back into that same
control.

Code is simle:

If Not bolClosed Then
MsgBox "Please close the attached file.", _
vbOKOnly, "Attachment Error"
Me!MyControl.SetFocus
End If

Yet, the focus is not set back to 'MyControl' when this
finishes.

Any ideas on why?

Thanks!
 
could it be Me.MyControl.SetFocus ?

Fly Girl said:
OK, I'm really feeling like an idiot here and I need
someone to either tell me to get a grip or explain why
this won't work:

In the MyControl_AfterUpdate event of a control on a form
I want to evaluate criteria and if it's not met, then send
the user a message and dump them back into that same
control.

Code is simle:

If Not bolClosed Then
MsgBox "Please close the attached file.", _
vbOKOnly, "Attachment Error"
Me!MyControl.SetFocus
End If

Yet, the focus is not set back to 'MyControl' when this
finishes.

Any ideas on why?

Thanks!
 
So, by putting this in the _BeforeUpdate event I got a
message saying that I needed to save the field before I
could use the SetFocus method.

However, if I try to save this field (an OLE field) I get
another message that says that code in the BeforeUpdate or
OnValidation (?) events are preventing me from saving the
record at this time.

I was trying to use this code to get around the fact that
MyControl.Action = acOLEClose doesn't seem to work. I'm
trying to trap users to prevent them from moving off of
the OLE control with the attachment (linked file) still
open.

Unfortunately, this doesn't seem to work, either.

Grrrr!
 
Fly Girl said:
OK, I'm really feeling like an idiot here and I need
someone to either tell me to get a grip or explain why
this won't work:

In the MyControl_AfterUpdate event of a control on a form
I want to evaluate criteria and if it's not met, then send
the user a message and dump them back into that same
control.

Code is simle:

If Not bolClosed Then
MsgBox "Please close the attached file.", _
vbOKOnly, "Attachment Error"
Me!MyControl.SetFocus
End If

Yet, the focus is not set back to 'MyControl' when this
finishes.

Any ideas on why?

It has to do with the sequence of events. The AfterUpdate event occurs
before the control has lost focus, but as it is about to. The SetFocus
call does nothing because the control still has the focus, but then the
action to move the focus to the next control happens anyway.

If you don't want to leave the control, use the BeforeUpdate event and
cancel the event if you're not happy:

Private Sub MyControl_BeforeUpdate(Cancel As Integer)

If Not bolClosed Then
MsgBox "Please close the attached file.", _
vbOKOnly, "Attachment Error"
Cancel = True
End If

End Sub
 
Hi,

Do you mean you want to close an application started by OLE control's
acOLEActivate action?

Would you post the logic/structure of your application? So I can do some
researching for you; for Word object, we can try the code below to close it:


Dim objWord As Word.Application
Dim objDoc As Word.Document

Set objWord = GetObject(, "Word.Application")
Set objDoc = objWord.ActiveDocument

objDoc.Close SaveChanges:=wdSaveChanges

objWord.Quit SaveChanges:=wdSaveChanges

Set objWord = Nothing


Please feel free to reply to the threads if you have any concerns or
questions.



Sincerely,

Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
| Content-Class: urn:content-classes:message
| From: "Fly Girl" <[email protected]>
| X-Tomcat-NG: microsoft.public.access.formscoding
|
| OK, I'm really feeling like an idiot here and I need
| someone to either tell me to get a grip or explain why
| this won't work:
|
| In the MyControl_AfterUpdate event of a control on a form
| I want to evaluate criteria and if it's not met, then send
| the user a message and dump them back into that same
| control.
|
| Code is simle:
|
| If Not bolClosed Then
| MsgBox "Please close the attached file.", _
| vbOKOnly, "Attachment Error"
| Me!MyControl.SetFocus
| End If
|
| Yet, the focus is not set back to 'MyControl' when this
| finishes.
|
| Any ideas on why?
|
| Thanks!
|
 
Back
Top