473,789 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A97 code causes keyboard loss

MLH
Running the following code produces NO error, but renders
my keyboard incapable of typing. I can use the mouse to
open the class module & look at it. But if I try to type in it -
nothing happens. I can open other apps with the mouse
and type in them, but I have to close the open database
and reopen before Access will let me resume typing.

10 Dim i As Integer, Msg As String, RetVal
20 On Error Resume Next
30 DoEvents
40 Kill ("c:\windows\IP data.sys")
50 On Error GoTo Err006
60 RetVal = Shell("c:\windo ws\system32\cmd .exe,0")
70 SendKeys "ipconfig /all > c:\MyDir\IPdata .sys~", True
80 SendKeys "exit~", True
90 AppActivate "Microsoft Access"
95 Exit Sub
Nov 13 '05 #1
9 1451
MLH
Running just the following locks my keyboard hopelessly.
Ideas?

Private Sub Command0_Click( )
Dim i As Variant
i = DoEvents

End Sub

Nov 13 '05 #2
MLH
Sorry, problem went away with a reboot.
Dunno what was happening. Wouldn't
have bothered you all if I had known it
was a glitch.

pls excuxe
Nov 13 '05 #3
MLH wrote:
Sorry, problem went away with a reboot.
Dunno what was happening. Wouldn't
have bothered you all if I had known it
was a glitch.

pls excuxe


Nevertheless you shouldn't use SendKeys like that, there's no guarantee
those keystrokes will go to the application you want them to. Shell out
the command you want to or if it's an internal dos command then use
Shell Environ("COMPSE C") & " /C <command>" as that will give you the
command interpreter for whatever system you're on, be it command.com,
4dos.com, ndos.com or cmd.exe, etc.

If you require more than one command then put them in a batch file and
shell to that.

I used to insert error trapping code using Sendkeys in Access 2.0 (later
versions have a module object) and I tried the same thing in VB once,
the copying and pasting of procedure names (done using highlighting)
went into Explorer once instead of my app, made a right mess of my files.

--
[OO=00=OO]
Nov 13 '05 #4
MLH
So, replace this line #60
60 RetVal = Shell("c:\windo ws\system32\cmd .exe,0")
using the one listed below?

10 Dim i As Integer, Msg As String, RetVal
20 On Error Resume Next
30 DoEvents
40 Kill ("c:\windows\IP data.sys")
50 On Error GoTo Err006
60 Shell Environ("COMPSE C") & " /C ipconfig /all > c:\MyDir\IPdata .sys"
90 AppActivate "Microsoft Access"
95 Exit Sub
I'll have a go at it.
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxx

Nevertheless you shouldn't use SendKeys like that, there's no guarantee
those keystrokes will go to the application you want them to. Shell out
the command you want to or if it's an internal dos command then use
Shell Environ("COMPSE C") & " /C <command>" as that will give you the
command interpreter for whatever system you're on, be it command.com,
4dos.com, ndos.com or cmd.exe, etc.

If you require more than one command then put them in a batch file and
shell to that.

I used to insert error trapping code using Sendkeys in Access 2.0 (later
versions have a module object) and I tried the same thing in VB once,
the copying and pasting of procedure names (done using highlighting)
went into Explorer once instead of my app, made a right mess of my files.

Bummer - I'm sure that's an experience you'll have a hard time
forgetting.
Nov 13 '05 #5
MLH
Running the following gave me runtime error #53,
File Not Found on line #60...
C:\MyDir does exist.
Private Sub Command0_Click( )
10 Dim i As Integer, Msg As String, RetVal
30 DoEvents
60 Shell Environ("COMPSE C") & " /C ipconfig /all >
c:\MyDir\IPdata .sys"
DoEvents

End Sub

Nov 13 '05 #6
MLH wrote:
Running the following gave me runtime error #53,
File Not Found on line #60...
C:\MyDir does exist.
Private Sub Command0_Click( )
10 Dim i As Integer, Msg As String, RetVal
30 DoEvents
60 Shell Environ("COMPSE C") & " /C ipconfig /all >
c:\MyDir\IPdata .sys"
DoEvents

End Sub


COMSPEC, not COMPSEC :-)

--
[OO=00=OO]
Nov 13 '05 #7
MLH
I thought that might be it. Before I made the post,
I checked A97 help. Point of Fact: There ain't
none for "Shell Environ". Only after I made the
post did I realize that Shell and Environ were 2
separate commands. How do we get away with the Shell
command not having its argument(s) enclosed in (parentheses)?

BTW, the thing works now. Reading help on Shell though,
I'm still wondering if I may find myself in a race condition
sometime - having commands after the Shell command that
expect the file to be there trying to open it before DOS is
finished doing its job. I have stuck a DoEvents line in there
after the Shell line. And I suppose I could loop between
Dir / sleep / Dir / sleep until the file was there. Hasn't been
a problem yet though.

COMSPEC, not COMPSEC :-)


Nov 13 '05 #8
MLH <CR**@NorthStat e.net> wrote in
news:aj******** *************** *********@4ax.c om:
I thought that might be it. Before I made the post,
I checked A97 help. Point of Fact: There ain't
none for "Shell Environ". Only after I made the
post did I realize that Shell and Environ were 2
separate commands. How do we get away with the Shell
command not having its argument(s) enclosed in (parentheses)?
Shell() is a function, which returns a value.

But if you aren't using the return value, it can be called as a
command, without the parentheses, just like any other command.

This is garden-variety VBA, not something specific to Shell().

I make a practice of never just using these commands baldly, but
instead use Call:

Call Shell ([whatever])

That forces the use of the parens, and then you no longer see any
apparent inconsistency.
BTW, the thing works now. Reading help on Shell though,
I'm still wondering if I may find myself in a race condition
sometime - having commands after the Shell command that
expect the file to be there trying to open it before DOS is
finished doing its job. I have stuck a DoEvents line in there
after the Shell line. And I suppose I could loop between
Dir / sleep / Dir / sleep until the file was there. Hasn't been
a problem yet though.


I have found that it is just better to have Shell() call a batch
file, since all the commands within the batch file will execute
sequentially.

If you need to do something in VBA *after* the Shell() command
finishes, then you have to use ShellAndWait, or some other form of
looping that pauses execution until the Shell instance closes.

But, looking at the bigger picture, excessive reliance of Shell()
suggest to me that you've designed your app incorrectly. Shell()
should be used exceedingly sparingly, and only for those things that
you cannot use VBA code for (which are very few).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #9
MLH
Good advice.
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3554
by: Yeah | last post by:
I wish to use a drop box where each Option will not take the user to a web page - but a certain location on the same page the drop box exists. For example, Option 1 would take the user to "Chapter 1", Option 2 would be "Chapter 2", and so on. All destinations are on the same page. I already have <A NAME="#ChapterX"> tags placed in the appropriate places in the document. (A no-GO button drop box is preferred.) How do I achieve this?
2
3354
by: Dutchy | last post by:
Hi there, After spending several hours trying all I could imagine and search for in Google I gave up. In a continuous form I want to sort the choosen column by clicking the header (label) of that column. I even want to sort up and down if one clicks again on the same header. No problem so far, all works well for one column. Now I want to sort on the first choosen column ASC or DESC and additionally on a second column ASC. I use the...
8
2950
by: MLH | last post by:
I use a mouse-down procedure to trap right mouse clicks and CTRL-Right mouse clicks. Running the procedure must put honey or some other sticky substance into my keyboard because subsequent RightMouseClicks run as if they were CTRL-RightMouseClicks I have to close the form and reopen it to clear this behavior. Then, after the first CTRL-RightMouseClick, it starts all over again.
2
2940
by: Travis | last post by:
Hi everyone, I'm using the System.Drawing.Imaging.Bitmap to retrieve and modify the metadata tags (user comments, keywords etc) of JPEGS. I was wondering if changing these tags in any way degrades the image quality of the JPEG. I am using SetPropertyItem to change the tag value and then calling the Save method to save the JPEG under a different name (you have to do this because GDI holds a lock on the original file).... If there is...
1
6825
by: Louis Cypher | last post by:
I'm working on an application (OEM) using c# that uses input from a keyboard and a USB Barcode Scanner. I need to be able to identify keystrokes from the barcode scanner and remove them from the message queue, regardless of what application has focus. I can identify the keystrokes and input device by registering for raw input (RegisterRawInputDevices) and processing the WM_INPUT message. This gives me the keystrokes and the ability to...
1
11236
by: Louis Cypher | last post by:
I'm working on an application (OEM) using c# that uses input from a keyboard and a USB Barcode Scanner. I need to be able to identify keystrokes from the barcode scanner and remove them from the message queue, regardless of what application has focus. I can identify the keystrokes and input device by registering for raw input (RegisterRawInputDevices) and processing the WM_INPUT message. This gives me the keystrokes and the ability to...
15
2038
by: Jason Doucette | last post by:
If you have two overloaded functions: double maximum(double a, double b, double c); int maximum(int a, int b, int c); They work fine if you call maximum() with all arguments as doubles, or all as ints. But, if you mix up doubles with ints in the argument list, it doesn't know which maximum() to call... but only one could possibly match -- the one that takes doubles.
3
4495
by: kettle | last post by:
Hi, I have a simple web page which is composed of a flash audio player (jwmp3player) and a form with a textarea box. I have noticed some very odd behaviour which I cannot puzzle out. If I click on the flash mp3 player to play an audio file, then try to click on the textarea and type in some text, I am unable to enter anything. I can move the cursor around the textarea but the keyboard focus will not change, as it appears to be stuck...
13
8759
by: andypb123 | last post by:
Hello, The onchange event fires in IE6 in a SELECT element when scrolling through the list with the up and down arrows on the keyboard. In Firefox it only fires after you hit the enter key, which is the behaviour I want make happen in IE. Does anyone know how to accomplish this? Thanks a lot Andy Birchall
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.