Hi folks;
I spent a little while some time ago building a touchscreen data entry interface into an Access 2003 form. I'm not too experienced in VBA at all so I was quite happy when I came up with a reasonably elegant solution, especially given that there's multiple text boxes involved. Each of the "keys" on the screen keyboard is a cmd button with its letter as a nice big caption on the front. The Mouse Down event triggers a bit of code:
Function addletter()
Screen.Previous Control.SetFocu s
Screen.ActiveFo rm.ActiveContro l.SelStart = 0
SendKeys "({END})" & Screen.Previous Control.Caption
End Function
The whole SelStart and "({END})" thing is a workaround to remove the highlighting you get when you switch focus to a filled text box, since we all know what happens if you highlight a bunch of text and then press "a"....
The Spacebar button was a bit trickier, I worked the Mouse Down event to run the following:
Function addspace()
Screen.Previous Control.SetFocu s
Screen.ActiveFo rm.ActiveContro l = Screen.ActiveFo rm.ActiveContro l & " "
Screen.ActiveFo rm.ActiveContro l.SelStart = Len(Screen.Acti veForm.ActiveCo ntrol)
End Function
Still not quite sure how it works but the space at the end of the text stays there, which is the main thing.
BUT... I have a problem. Under normal typing it's fine, you can type words followed by a single space followed by another word and it works great. But if the user accidentally presses space twice then sometimes the focus goes back to the text box where it belongs but sometimes it stays on cmdSpacebar.. As far as I can tell it's totally random, there's no telling when it might do what. And when it does stay on cmdSpacebar you click a letter key it tries to do a SendKeys on the PreviousControl (being, in this case, cmdSpacebar) and the whole thing comes crashing down. Does anybody know what's going on here and how I can program this little bug out of my database?
Thanks!
6 4476
This sounds kinda complex. I've noticed many threads with comments about SendKeys, and that they should be avoided. Sometimes can't, but sometimes you can.
Here's an idea that seems to solve all your issues. - Option Compare Database
-
Option Explicit
-
-
-
Dim tbx As TextBox
-
Dim strInputSpace As String
-
-
Private Sub cmdA_Click()
-
strInputSpace = strInputSpace & "A"
-
tbx = strInputSpace
-
End Sub
-
-
Private Sub cmdB_Click()
-
strInputSpace = strInputSpace & "B"
-
tbx = strInputSpace
-
End Sub
-
-
Private Sub cmdC_Click()
-
strInputSpace = strInputSpace & "C"
-
tbx = strInputSpace
-
End Sub
-
-
Private Sub cmdSpace_Click()
-
strInputSpace = strInputSpace & " "
-
tbx = strInputSpace
-
End Sub
-
-
Private Sub txtTextBox1_GotFocus()
-
cmdSmallControl.SetFocus
-
Set tbx = txtTextBox1
-
strInputSpace = Nz(txtTextBox1, "")
-
End Sub
-
-
Private Sub txtTextBox2_GotFocus()
-
cmdSmallControl.SetFocus
-
Set tbx = txtTextBox2
-
strInputSpace = Nz(txtTextBox2, "")
-
End Sub
cmdSmallControl is a command button 1 pixel square, visible, in the upper left corner of the form. It is used for SetFocus to keep any other control from appearing to have the focus.
Of course, you would standardize the keys into a function or subroutine. You can have as many textboxes as needed. A "Shift" key would be easy to impliment. Whole keyboard could change to UCase for one "keypress".
Don't know yet how to select portions of text, or position cursor, but arrow keys and double-click in textbox would be my start.
Sounds like it might work, but I wanted above all to avoid having a separate bit of code unique to each key on the on-screen keyboard. That way, if you have to make one change you have to make 26! The way I do it (with the key caption) means I can have the same macro on every key that runs the same bit of code. As a whole it works perfectly apart from that damned spacebar bug! I think I'll see if I can do it with straight coding on cmdSpace rather than going via a macro, maybe that's the problem... Thanks though, it certainly helps to look in different directions!.
I had figured that you would write a subroutine and each letter would call that common subroutine. Same code for all keys. Or you could capture the event through key preview for the form.
I do remember somewhere a tricky way to have Access treat multiple commands as an array of controls. Maybe someone else remembers that if you are interested.
All input gratefully received! I have managed to draw a bit more of a bead on the problem. If you click the cmdSpacebar slowly (once a second) you can keep going 'til the cows come home. The problem only crops up if you click it rapidly, a bit faster than a normal double-click that is. Is there a way of maybe Calling the event or using DoEvents?
Fixed! I just changed the event that fires the procedure from On Mouse Down to Got Focus. As a bonus, I no longer get that nasty flicker on the button as it's clicked then suddenly has the focus snatched away from it. Cheers folks!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ted Mayett |
last post by:
OK. Here is a glitch, sorry if this has been mentioned before.
This is an erratic glitch. I am now up to three other people besides
myself who have been able to see this glitch. It seems it only
happens in IE. And the <hr> causes this thing to happen.
Now, I have ~tried~ to make this glitch, and that is tough to do. I
had did it that one time, and I should have saved the work. But I
didn't save the work :(
|
by: Mr. Bungle |
last post by:
I would like to send email automatically via a command button. I have
accomplished this just fine through the following code: (Outlook
should already be open for reliable results)
Private Sub Command6_Click()
ReturnValue = Shell("Outlook.EXE", 1) ' Run Outlook
SendKeys "%(F)", True
SendKeys "W", True
SendKeys "M", True 'Open New Message
SendKeys "randomemail@harbornet.com", True '<-- Email Address
|
by: RBohannon |
last post by:
I need to create a report in MS Word populated with data from A2K. I
have been asked to create the report in Word so that parts of it can be
edited as necessary later. The data in the report are in a table with
headings for each column, so converting an Access report to a Word doc
in RTF doesn't work because only the text is converted, not the table.
What I have tried so far, with some success, is to write the report
directly in Word....
|
by: George |
last post by:
Every time I used the Sendkeys command in my application the "Numlock"
turned off and I couldn't use the keypad to hit numbers......
The old code was:
Private Sub Command1_Click()
SendKeys "{DOWN}"
SendKeys "^{END}"
SendKeys "{TAB}"
End Sub
|
by: Wayne Gibson |
last post by:
Hi,
Was wondering if somebody could help.. I'm trying to use Sendkeys on a
Windows forms.
I have entered the following command to simulate a CTRL+ALT+1..
System.WindowsForms.SendKeys.Send("^%1");
This didn't work, so I then tried..
| |
by: Bryan |
last post by:
I am writing a C# Windows App that updates out Excel reports' modules. The
app is complete, but has a problem. The only way MS allows you to unprotect
the VBA code in Excel is to do it by hand or sendkeys.
I hate using SendKeys, but I am forced to use them. Anyway, I have written a
function that will unprotect the VBA code in the current work book. It works
about 60% of the time. For some reason it gets out of sync and the SendKeys
don't...
|
by: GrantS |
last post by:
I need to use a sendkeys key combination to automate the "accept
files" that a remote user wants to send to me via Windows messenger. I
am using automation to work with Windows Messenger client in a
Winforms C# application.
I have tried a number of code segment combinations for ALT T
combination without success. The combinations might be correct but it
might be failing for some other reason.
My Attempts:
|
by: Michael Maes |
last post by:
Hello,
I'm invoking successive
SendKeys.SendWait("{BACKSPACE}")
SendKeys.SendWait("{DELETE}")
in a loop.
The issue is that it causes a Beep on every Pass.
Setting the 'Handled = True' on the Control does prevent the Beep, but
|
by: dtshedd |
last post by:
I have a database with hundreds of embedded photos (Microsoft Photo
3.0) Many are larger than 1 MB. I tried Stephen Lebans macro but it
did not work probably for the aforementioned reasons
Now I am trying to use the copy portion of Stephens macro and then
open MS Paint using Sendkeys to Paste and save.
The Sendkeys method is opening the Paint app but not executing the
paste command. Wondering what I am doing wrong. I have only ever...
|
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...
|
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,...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |