You do realize that if you need an onboard keyboard, one is built into Windows, right? Depending upon your version, how you get to it may be slightly different. But for Vista or 7, you could simply open the start menu and type
keyboard and it will come right up.
The reason I ask is because to me, this sounds more like a homework assignment than anything, and the current school year (in the US) has just started, or is just about to start depending upon district/institution.
Now, assuming this is not homework...
Please verify... are you saying you are USING the system/built-in onscreen keyboard, or that you are for some reason needing to BUILD one yourself? I can see the benefit in doing it for practice, but I am just wondering about practicality of duplicating a built-in system functionality.
So with the code you've posted, what have you tried? What isn't working? What errors are you receiving? Please detail what you are doing, what you are expecting, and what you are getting.... in other words, what's the difference between what you EXPECT to happen, and what is actually happening? Also, if it just isn't working right, have you tried stepping through the code?
How to step through code: Move your mouse cursor within the procedure... well, in this case, you'd need to call the function from a button or another procedure. Since yours is a function, and you're actually building the keyboard, I guess, then you'd want to run this off the button click. So behind every button on your form, you'd call the same function like this:
First of all, I'd imagine it best to use a public variable for Form and Control like this:
Code:
Public frm As Form
Public ctl As Control
Then build your function to do your deal:
Code:
Private Function TypeAlphaNum() As String
Set Form = Forms(Form.Name)
Set ctl = frm.ActiveControl
Dim strKey As String ' moved this out of the calling function,
' b/c if you use ActiveControl, you won't need to pull in that name...
' assuming the function can reside within the form.
strKey = ctl.Name
'Do the rest of the function stuff here
End Sub
Then call it from each button:
Code:
Private Sub Button1_Click()
Call YourFunction
'Or if you really are returning a value - which I don't see that you are, so it probably should be a procedure anyway
Msgbox YourFunction
End Sub
Private Sub MyButton_Click()
Call YourFunction
'Or if you really are returning a value - which I don't see that you are, so it probably should be a procedure anyway
Msgbox YourFunction
End Sub
In the end, the current code, as it is, is far too complicated, I think, if you're just wanting to capture the current control, and do something with it. I think I saw something in there about the previous control. What do you want to do with the previous control?
So really it boils down to this:
1. What do you want to do? - what do you want the form/controls to do?
2. What has the current code done? Has it worked at all? If so, what happened? Was that expected/desired?
If you just copied and pasted the code from a book (or typed from reading a book) or pasted from online somewhere, and just ran it without applying it to your specific situation, then you're NOT likely to get the results you expect.
"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57