Solved

Access 2003 SendKeys not working Windows 7

Posted on 2010-08-23
15
3,184 Views
Last Modified: 2012-05-10
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!!!!!
0
Comment
Question by:kwarta
  • 6
  • 4
  • 3
  • +2
15 Comments
 
LVL 12

Expert Comment

by:mcv22
ID: 33506626
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 33506700
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
 

Author Comment

by:kwarta
ID: 33506828
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 33506907
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
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 33507514
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33508193
Can you tell us what you are using Sendkeys for?

Perhaps there is an alternative.
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 33516012
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33516804
OK,

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

;-)

Jeff
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 33516825
Hey!  I wasn't saying you're not welcome!
;-)
Graham
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33516917
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
 

Author Comment

by:kwarta
ID: 33522672
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
 

Author Comment

by:kwarta
ID: 33522678
And thanks guys :))
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 33526387
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
 

Author Comment

by:kwarta
ID: 33526625
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
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 500 total points
ID: 33526671
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

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now