Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flexibility and the setfocus command

Status
Not open for further replies.

pronet74

MIS
Mar 9, 2004
192
US
Have any of you noticed or had problems with setting focus to a control with flexibility? I'll do a set focus on a control, and then take the value of that control only to error out saying 'A VBA Setfocus request could not be completed'. This happens quite a bit, for example the following code:

Private Sub LineNo_GotFocus()
TotalLineNumbers = LineNo.Text - 1
If MsgAnswer = 6 Then
For I = 1 To TotalLineNumbers
LineNo.Text = I
I = I + 1
SendKeys "{Tab}"
ReqDate.SetFocus
ReqDate.Text = NewReqDate
NewReqDate = ""
OldReqDate = ""
SendKeys "{Enter}"
Next
MsgAnswer = 0
I = 0
End If
End Sub

The only thing I can think of is because it's after the tab. How does VBA interpret this? The error comes on the ReqDate.text = NewReqDate
 
It's a little bit clunky, but you will save yourself a great deal of trouble if you use the SetFocus command as the last command in an event and then continue your code in the GotFocus event of the control you just set focus on. This problem has something to do with concurrency I believe. Also, the SendKeys command runs synchronously and can cause the same sort of problems.

To use this technique you can set a module level flag variable that each event procedure checks to see if the code is in "automation" mode. I have tried many times to get around this, but I eventually gave up because I got tired of trying to debug code that intermitently works.

Another word of advice would be to avoid sharing Flexibility code between multiple users. This can cause intermitent erros as well. If users will rarely share a form don't worry about it to much, but if you have 10 users performing order entry tasks make sure each user has there own folder in the vbaprj project folder. Just my extra 2 bits.

Scott Travis
infoSpring, LLC.
 
Thanks for your reply. This really sucks then. I noticed the sendkeys command is touchy, but if you do a sendkeys "{command}", true Then it totally locks up.

I am going to have to mess with my code a little more to find a work around.
 
To solve some sendkeys problems you can create a small application executable with no user interface that accepts a sendkeys {command}, waitFlag, and repeatValue. Then just call the application with the parameters from within Flexibility. I have found that this is a good work around to some of my sendkeys woes.

Scott Travis
infoSpring, LLC.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top