Setting Focus and Using SendKey

G

Guest

I'm trying to set the OnClick property for a certain button on my form which
will prompt the activation of several other control buttons and hyperlinks.
I've tried the following code with two of the command buttons so far, but the
SendKey method will only work within the first document that is opened. I
don't want SendKey doing anything in the other non-Access documents.

Forms![CloseoutDocumentsCheckList]![SeeBlankTemplate].SetFocus
SendKeys "{ENTER}", True
Forms![CloseoutDocumentsCheckList]![PreviewTableofContents].SetFocus
SendKeys "{ENTER}", True

The first two lines of this code work perfectly, but the last two lines work
independently. The focus is set to the next command button
(PreviewTableofContents) but the SendKeys method applies its actions to the
document opened resulting from the use of the first command
button(SeeBlankTemplate).

I've read that SendKey can yield unreliable results, but I don't understand
why other than because of its inconsistency.

Any suggestions?

Nicole
 
M

Marshall Barton

Nicole said:
I'm trying to set the OnClick property for a certain button on my form which
will prompt the activation of several other control buttons and hyperlinks.
I've tried the following code with two of the command buttons so far, but the
SendKey method will only work within the first document that is opened. I
don't want SendKey doing anything in the other non-Access documents.

Forms![CloseoutDocumentsCheckList]![SeeBlankTemplate].SetFocus
SendKeys "{ENTER}", True
Forms![CloseoutDocumentsCheckList]![PreviewTableofContents].SetFocus
SendKeys "{ENTER}", True

The first two lines of this code work perfectly, but the last two lines work
independently. The focus is set to the next command button
(PreviewTableofContents) but the SendKeys method applies its actions to the
document opened resulting from the use of the first command
button(SeeBlankTemplate).

I've read that SendKey can yield unreliable results, but I don't understand
why other than because of its inconsistency.


SendKeys has bugs, (e.g. changes NumLock setting)
AND it is inconsistent because there is no way to tell it
where you are sending the key strokes.
Bottom line - NEVER USE SendKeys for anything!

If all you want to do is run a command button's Click event
procedure, then just call it:

SeeBlankTemplate_Click

or, if the button is on a separate, open form:

Forms!CloseoutDocumentsCheckList!SeeBlankTemplate_Click
 
G

Guest

Dear Marshall:

When entering your suggested code as is, I get the Compile error...

"Expected: = "

So, I modify the code to read...

Forms!CloseoutDocumentsCheckList!SeeBlankTemplate_Click = True

This compiles with no problem, but when running the code I get Run-time
error '2465' "Startup can't find the field 'SeeBlankTemplate_Click'.

It's like it doesn't even recognize the Click procedure but wants to make
the word click a part of the name of my command button. I can not for the
life of me figure out how to use it.

Nicole

Marshall Barton said:
Nicole said:
I'm trying to set the OnClick property for a certain button on my form which
will prompt the activation of several other control buttons and hyperlinks.
I've tried the following code with two of the command buttons so far, but the
SendKey method will only work within the first document that is opened. I
don't want SendKey doing anything in the other non-Access documents.

Forms![CloseoutDocumentsCheckList]![SeeBlankTemplate].SetFocus
SendKeys "{ENTER}", True
Forms![CloseoutDocumentsCheckList]![PreviewTableofContents].SetFocus
SendKeys "{ENTER}", True

The first two lines of this code work perfectly, but the last two lines work
independently. The focus is set to the next command button
(PreviewTableofContents) but the SendKeys method applies its actions to the
document opened resulting from the use of the first command
button(SeeBlankTemplate).

I've read that SendKey can yield unreliable results, but I don't understand
why other than because of its inconsistency.


SendKeys has bugs, (e.g. changes NumLock setting)
AND it is inconsistent because there is no way to tell it
where you are sending the key strokes.
Bottom line - NEVER USE SendKeys for anything!

If all you want to do is run a command button's Click event
procedure, then just call it:

SeeBlankTemplate_Click

or, if the button is on a separate, open form:

Forms!CloseoutDocumentsCheckList!SeeBlankTemplate_Click
 
M

Marshall Barton

Sorry, I made a big mistake. It should be:

Forms!CloseoutDocumentsCheckList.SeeBlankTemplate_Click

In case you can't see the difference, there's a dot in place
of the second !

Such a little thing makes s big difference ;-)
--
Marsh
MVP [MS Access]

When entering your suggested code as is, I get the Compile error...

"Expected: = "

So, I modify the code to read...

Forms!CloseoutDocumentsCheckList!SeeBlankTemplate_Click = True

This compiles with no problem, but when running the code I get Run-time
error '2465' "Startup can't find the field 'SeeBlankTemplate_Click'.

It's like it doesn't even recognize the Click procedure but wants to make
the word click a part of the name of my command button. I can not for the
life of me figure out how to use it.

Marshall Barton said:
Nicole said:
I'm trying to set the OnClick property for a certain button on my form which
will prompt the activation of several other control buttons and hyperlinks.
I've tried the following code with two of the command buttons so far, but the
SendKey method will only work within the first document that is opened. I
don't want SendKey doing anything in the other non-Access documents.

Forms![CloseoutDocumentsCheckList]![SeeBlankTemplate].SetFocus
SendKeys "{ENTER}", True
Forms![CloseoutDocumentsCheckList]![PreviewTableofContents].SetFocus
SendKeys "{ENTER}", True

The first two lines of this code work perfectly, but the last two lines work
independently. The focus is set to the next command button
(PreviewTableofContents) but the SendKeys method applies its actions to the
document opened resulting from the use of the first command
button(SeeBlankTemplate).

I've read that SendKey can yield unreliable results, but I don't understand
why other than because of its inconsistency.


SendKeys has bugs, (e.g. changes NumLock setting)
AND it is inconsistent because there is no way to tell it
where you are sending the key strokes.
Bottom line - NEVER USE SendKeys for anything!

If all you want to do is run a command button's Click event
procedure, then just call it:

SeeBlankTemplate_Click

or, if the button is on a separate, open form:

Forms!CloseoutDocumentsCheckList!SeeBlankTemplate_Click
 

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