Access 2003 SendKeys not working Windows 7

The code worked fine in XP but in WIndows 7 it does not. I need a fix desperately for Access 2003 on Windows 7 for Send Keys. This is VBA

Sub MySendKeys(SendText As String, Optional WaitResponse As Boolean = False)
    'wrapper for Sendkeys which does not crash in the IDE under Windows Vista
    Set WshShell = CreateObject("WScript.Shell")
    VBA.WshShell.SendKeys SendText, WaitResponse
    Set WshShell = Nothing
End Sub

HELP!!!!!
kwartaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
GrahamMandenoConnect With a Mentor Commented:
Hi Kris
If these are action queries, here is a much better solution:
Dim qry As QueryDef
  Set qry = CurrentDb.QueryDefs(sQueryName)
  If Nz(sQueryParams, "") <> "" Then
    MyParameters = Split(sQueryParams, "|", -1, vbTextCompare)
    If MyParameters(0) <> "*UseQueryDef*" Then
      For nParameter = 0 To UBound(MyParameters)
        qry.Parameters(nParameter) = MyParameters(nParameter)
      Next
    End If
  End If
  qry.Execute dbFailOnError
--
Graham
0
 
mcv22Commented:
0
 
GrahamMandenoCommented:
When you say "it does not work", what do you mean?  Do you get an error?  Does it do anything?  Does it do the wrong thing?  "It does not work" is ot very informative!  :-)
One thing that looks wrong to me is the "VBA." on the fourth line.  Try changing it to:
    WshShell.SendKeys SendText, WaitResponse
By the way, any use of SendKeys should be avoided where possible.  99% of the time there is a better and more reliable way.
--
Graham
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
kwartaAuthor Commented:
Its Error 70
And its for my job I actually need to fix:

If Nz(sQueryParams, "") <> "" Then
        MyParameters = Split(sQueryParams, "|", -1, vbTextCompare)
       
        If MyParameters(0) = "*UseQueryDef*" Then
           
        Else
            For nParameter = 0 To UBound(MyParameters)
                SendKeys MyParameters(nParameter) & "{Enter}"
            Next
        End If
    End If

    For nLoop = 1 To nEnters
        SendKeys "{Enter}", False
    Next
0
 
rockiroadsCommented:
My first thoughts was its probably UAC. Really annoying but keep it as its something I think it helps being safe.
Anyways, there is this sample code here which may possibly help you. I haven't tried it so cannot vouch for it but it does check for o/s. http://www.tek-tips.com/viewthread.cfm?qid=1591816&page=9
0
 
GrahamMandenoCommented:
Can you please post the whole of the procedure contining this code?  It looks like you are supplying parameters to a query and it should certainly be easy (and MUCH better) to do this without SendKeys.
It is definitely the new security restrictions in Vista / Windows7 that is causing the problem.  Karl Peterson (long-time VB guru) has written a SendKeys replacement which calls the SendInput API to get around this problem.  Mcv22 posted the link to that code above - here it is again: http://vb.mvps.org/samples/SendInput
Download SendInput.zip from the link near the bottom of the page.
Don't worry that it's a VB6 project.  You don't need VB6 - just extract MSendInput.bas from the zip file and import it into your Acces VBA project.
But, like I said, I recommend you try for a workaround to avoid and form of SendKeys.
--
Graham
0
 
Jeffrey CoachmanMIS LiasonCommented:
Can you tell us what you are using Sendkeys for?

Perhaps there is an alternative.
0
 
GrahamMandenoCommented:
Hi Jeff
Yeah, that's what I said :-)
It sounds like kwarta is opening a parameter query and using SendKeys to supply the parameters.  When s/he supplies the rest of the code we should be able to provide a *good* solution.
Cheers,
--
Graham
0
 
Jeffrey CoachmanMIS LiasonCommented:
OK,

I'll step aside, as I know that you and rr can surely handle this...

;-)

Jeff
0
 
GrahamMandenoCommented:
Hey!  I wasn't saying you're not welcome!
;-)
Graham
0
 
Jeffrey CoachmanMIS LiasonCommented:
Oh, I'll be watching...
;-)

Again, I know you guys can handle it, ...no need to confuse the asker with another Expert chiming in...

;-)

Jeff
0
 
kwartaAuthor Commented:
Sorry for the long wait lol OK so I went with this solution but ran into a problem with window 7 and access 2003. It being on

If Nz(sQueryParams, "") <> "" Then
        MyParameters = Split(sQueryParams, "|", -1, vbTextCompare)
       
        If MyParameters(0) = "*UseQueryDef*" Then
           
        Else
            For nParameter = 0 To UBound(MyParameters)
             If Not init Then
        If IsDevEnv() Then
            IsIDEUnderVista = (OsVersion() >= 6)
            If IsIDEUnderVista Then Set WshShell = CreateObject("WScript.Shell")
        End If
        init = True
    End If
   
    If Not IsIDEUnderVista Then
        VBA.SendKeys MyParameters(nParameter) & "{Enter}"
    Else
        WshShell.SendKeys MyParameters(nParameter) & "{Enter}"
               ' SendKeys MyParameters(nParameter) & "{Enter}"
            Next
        End If
    End If
   

   
    'send some CR's if requested
   
    'Kris 20100823 - Send Keys fix
   
    For nLoop = 1 To nEnters
       
        'SendKeys "{Enter}", False
         If Not init Then
        If IsDevEnv() Then
            IsIDEUnderVista = (OsVersion() >= 6)
            If IsIDEUnderVista Then Set WshShell = CreateObject("WScript.Shell")
        End If
        init = True
    End If
   
    If Not IsIDEUnderVista Then
        VBA.SendKeys "{Enter}", False
    Else
        WshShell.SendKeys "{Enter}", False
    End If
    Next



Private Function IsDevEnv() As Boolean
   Dim x As Long
   Debug.Assert Not TestIDE(x)
   IsDevEnv = x = 1
End Function

Private Function TestIDE(x As Long) As Boolean
   x = 1
End Function



Hope that is a good solution also - the issue was that queries are running queries parameters are popping up and the send keys feeds the parameters. Now this is an inhouse app that runs and they don't want to delve in and fix it or upgrade it so ?

I just started so ......... on to another project :)
0
 
kwartaAuthor Commented:
And thanks guys :))
0
 
GrahamMandenoCommented:
Hi Kris
I don't think it is a good solution.  As I (and others) have said, SendKeys should be used only as a very last resort.
It appears you have still not posted the whole of the procedure containing this code.  It seems evident that you are opening queries with parameters.  Are these action queries (update/append/delete/etc), or are they select queries that you are opening in datasheet view?
--
Graham
 
0
 
kwartaAuthor Commented:
both select and update. As stated this is not my code and my boss does not want another solution just one that works with a different solution however if there was a different one I would love to present it. However I can't release more of their code esp with my user name lololol :))))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.