Solved

Access 2003 SendKeys not working Windows 7

Posted on 2010-08-23
15
3,203 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
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.

 
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

910 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