Problems creating a popup keypad in access.
October 31, 2006 8:29 AM Subscribe
I am developing an access app for a UMPC, and because of the lack of a keyboard, I want to make a keypad number entry popup.
I am now struggling with the getting it to work. My current method is
Private Sub Button1_Click()
DoCmd.GoToControl "PackQuantity"
SendKeys "1", no
End Sub
and then repeat for each button. Currently I can only get it to put one number in the text box, because each press of the button erases the existing data. I have tried adding a line like:
SendKeys "{End}", no
Or instead of end, Right, but it does about the same thing.
I know this probably isn't the best way to do it, but its all I've come up with so far. Any suggestions would be welcome at this point.
I am now struggling with the getting it to work. My current method is
Private Sub Button1_Click()
DoCmd.GoToControl "PackQuantity"
SendKeys "1", no
End Sub
and then repeat for each button. Currently I can only get it to put one number in the text box, because each press of the button erases the existing data. I have tried adding a line like:
SendKeys "{End}", no
Or instead of end, Right, but it does about the same thing.
I know this probably isn't the best way to do it, but its all I've come up with so far. Any suggestions would be welcome at this point.
Response by poster: No reason at all. I just need to get the numbers into a string in some way without a keyboard.
posted by JonnyRotten at 8:51 AM on October 31, 2006
posted by JonnyRotten at 8:51 AM on October 31, 2006
Functional decomposition is your friend.
Second, you have no need to use sendkeys: you just want to fill in the text box. sendkeys is more than you need and a potential stumbling block.
Presumably, there is a way to get the text currently in the box (textbox.getText(), perhaps?). Presumably there is also a textbox function to set the text( textbox.setText( string), perhaps? ).
To append arbitrary text, there's either an existing function already on textbox (look!) or it's simply a matter of calling
textbox.setText( textbox.getText() + suffix )
Now, decompose this. First an append function:
Private Sub appendToTextBox( Textbox t, String s )
t.setText( t.getText() + s )
End Sub
Now write your button code in terms of this:
Private Sub Button1_Click()
appendToTextBox( myTextBox, "1" )
End Sub
Now find a way to sub-class the button type, passing the text to append in the constructor; I have no idea how this works in VB, but find out. This will allow you to encapsulate both the button display (the "1" button ought to display a "1", yes?) and behavior (by overriding onClick() ).
It will also allow you to make an array of button subclasses:
MyTextBox = new textBox;
MyTextButton[] = { MyTextButton( MyTextBox , "1" ), MyTextButton( MyTextBox "2" ), MyTextButton( MyTextBox, "3" ) ....
More elegant and stable compositions of the sub-objects is left as an exercise. (Hint: tie the textbox and the buttons together in another object, a "Keypad".)
posted by orthogonality at 9:12 AM on October 31, 2006
Second, you have no need to use sendkeys: you just want to fill in the text box. sendkeys is more than you need and a potential stumbling block.
Presumably, there is a way to get the text currently in the box (textbox.getText(), perhaps?). Presumably there is also a textbox function to set the text( textbox.setText( string), perhaps? ).
To append arbitrary text, there's either an existing function already on textbox (look!) or it's simply a matter of calling
textbox.setText( textbox.getText() + suffix )
Now, decompose this. First an append function:
Private Sub appendToTextBox( Textbox t, String s )
t.setText( t.getText() + s )
End Sub
Now write your button code in terms of this:
Private Sub Button1_Click()
appendToTextBox( myTextBox, "1" )
End Sub
Now find a way to sub-class the button type, passing the text to append in the constructor; I have no idea how this works in VB, but find out. This will allow you to encapsulate both the button display (the "1" button ought to display a "1", yes?) and behavior (by overriding onClick() ).
It will also allow you to make an array of button subclasses:
MyTextBox = new textBox;
MyTextButton[] = { MyTextButton( MyTextBox , "1" ), MyTextButton( MyTextBox "2" ), MyTextButton( MyTextBox, "3" ) ....
More elegant and stable compositions of the sub-objects is left as an exercise. (Hint: tie the textbox and the buttons together in another object, a "Keypad".)
posted by orthogonality at 9:12 AM on October 31, 2006
What about...
dim Keylog as String
Private Sub Button1_Click()
Keylog = Keylog & "1"
End Sub
Private Sub Button2_Click()
Keylog = Keylog & "2"
End Sub
Private Sub ButtonDone_Click()
SendKeys Keylog
End Sub
That presumes you can send multiple keystrokes in one SendKeys though. Otherwise...
for a = 1 to Len(Keylog)
SendKeys Mid(Keylog, a, 1)
next a
posted by xvs22 at 9:15 AM on October 31, 2006
dim Keylog as String
Private Sub Button1_Click()
Keylog = Keylog & "1"
End Sub
Private Sub Button2_Click()
Keylog = Keylog & "2"
End Sub
Private Sub ButtonDone_Click()
SendKeys Keylog
End Sub
That presumes you can send multiple keystrokes in one SendKeys though. Otherwise...
for a = 1 to Len(Keylog)
SendKeys Mid(Keylog, a, 1)
next a
posted by xvs22 at 9:15 AM on October 31, 2006
I missed out DoCmd.GoToControl "PackQuantity". Not sure where that should go! What orthogonality said sounds like a sleeker way of doing it mind you.
posted by xvs22 at 9:20 AM on October 31, 2006
posted by xvs22 at 9:20 AM on October 31, 2006
This thread is closed to new comments.
posted by xvs22 at 8:44 AM on October 31, 2006