I want a form to open without receiving the focus

bcmarshall

Registered User.
Local time
Yesterday, 20:41
Joined
Jul 17, 2010
Messages
92
I created an internal Instant Messaging system through Access. The message form is a pop-up, but not Modal. The problem we're experiencing is that often the IM form opens while someone is in the middle of typing in a field on another form, and the characters being typed wind up in the IM field instead of where the user was typing when the IM form opened. They hit Enter to move to the next field without even looking up, and the half-string of characters intended for the form that was open is sent as a reply to the IM sender.

Is there a way to open that IM form without taking the focus from the form that had it before the IM opened?

As always, thanks in advance for your assistance.
 
I just play a sound when there is a message.
 
does the IM form has timer event on it?

you can save the name of the form when IM form is invoked, and set focus to it again.

dim strFormName as string
on error resume next
strFormName = Screen.ActiveForm.Name
If strFormName <> "" Then Forms(strFormName).Setfocus
 
Thank you for the suggestion. In general that might work, but my reality is that not every computer has sound, or has sound turned on. Although it's a good idea I just don't think it will work for all cases for me.
 
does the IM form has timer event on it?

you can save the name of the form when IM form is invoked, and set focus to it again.

dim strFormName as string
on error resume next
strFormName = Screen.ActiveForm.Name
If strFormName <> "" Then Forms(strFormName).Setfocus

I really like this suggestion because I think it will do what I need. If I use it on the timer event it seems I have to have a very short trigger for the time, maybe 10 ms or something so that it runs almost immediately after form opens. I assume that one of the instructions would of necessity be to set the timer interval to 0 to keep it from running repeatedly.

Does that all make sense?
 
does the IM form has timer event on it?

you can save the name of the form when IM form is invoked, and set focus to it again.

dim strFormName as string
on error resume next
strFormName = Screen.ActiveForm.Name
If strFormName <> "" Then Forms(strFormName).Setfocus

I tried this and it worked perfectly. I set TimerInterval to 5 ms and added a line in the code to reset TimerInterval to 0, and it does not seem to interrupt focus at all.

Thank you again.
 
does the IM form has timer event on it?

you can save the name of the form when IM form is invoked, and set focus to it again.

dim strFormName as string
on error resume next
strFormName = Screen.ActiveForm.Name
If strFormName <> "" Then Forms(strFormName).Setfocus
I want to amend my earlier comment. It works almost perfectly!

For test purposes I was using two fingers to toggle between two keys as fast as I could to simulate fast tying. The message box opened and about three characters made it onto the message form before the focus switched back.

I'm wondering if there's another way to accomplish this besides using the timer event, since clearly, even though I've set it now at 1 ms, there is still some delay that I would like to get rid of.

Can you think of another way to accomplish this without the timer event?
 
Can you tell us more about, or post a copy , of your IM system?
 
Can you tell us more about, or post a copy , of your IM system?

It's really tough to post because it's quite complex, but the greatly simplified version is that when a message is sent it's recorded in a table along with the recipient's UserName. There's a bit field called Acknowledged that defaults to False.

There's a hidden form that runs a sequence of events every 5 seconds, and one of those events is to do a lookup on the IM table to see if there are any unacknowledged messages for that User, and if there are the IM form opens, the message fills into the field, and the Acknowledged field is set to True.

There are dozens of refinements that stop it from running or cause it not to open under certain conditions, so posting the whole thing is really impossible, but essentially it looks to see if an IM is waiting every 5 seconds, and if there is one the form opens with the message in it.

I hope that's enough info.
 
still on your timer event, after disabling it for a while by setting TimerInterval = 0, you can undo any changes to your IM form by using Me.Undo.
then immediately switch back to the previous form.
 
still on your timer event, after disabling it for a while by setting TimerInterval = 0, you can undo any changes to your IM form by using Me.Undo.
then immediately switch back to the previous form.
Great! Another improvement. But is there some way to run this without the timer? I tried on Open and On Load but it didn't seems to want to work there. I'd like to remove the delay if possible, even if it's only 1 ms.
 
how is IM form being invoked, through timer or not?
 
how is IM form being invoked, through timer or not?
Not invoked through the IM form timer. There's a hidden form that runs a timer every five seconds, and that timer runs maybe a dozen different routines that cause different things to fire.

One of the things that happens on that hidden form timer event is to search the IM table to see if any messages are marked unacknowledged and are addressed to the user whose computer is running the routine. If one is found the IM form opens, but outside of your suggestions there has been nothing on the OnTimer event of that IM form itself.

The hidden timer simply opens the IM form if a match is found.
 
correct me if im, wrong the IM pop up if there are unacknowledge messages, and there are codes in this IM form that automatically set a field as acknowledged, is that it?

if that the case you can just set the fields in the IM as Locked, so it will not be altered.
 
correct me if im, wrong the IM pop up if there are unacknowledge messages, and there are codes in this IM form that automatically set a field as acknowledged, is that it?

if that the case you can just set the fields in the IM as Locked, so it will not be altered.
Yes, you are correct. That may be the solution. I'll try it and let you knot.

Thank you so much for your help.
 

Users who are viewing this thread

Back
Top Bottom