Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access 2003 SendKeys not working Windows 7

Posted on 2010-08-23
15
Medium Priority
?
3,371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

610 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