|
-
Jul 2nd, 2004, 11:58 AM
#1
Thread Starter
Banned
question on key hit and focus
Is there a way to tell which control has the focus?
I want to pass a control to a specific function only if it has focus.
Also my second question is...I want to use F7 as a "Sendkeys" or keydown event..but how do I check if this button is clicked.
I want it at the form level...
basically user hits F7 .. and the text box that has the focus calls a specific function that takes as a parameter that control.
THanks,
Jon
-
Jul 2nd, 2004, 01:18 PM
#2
Thread Starter
Banned
Re: question on key hit and focus
Err..I need a hasfocus..or an API that tells me what text box / control has the focus..
I took the majority of this from marty to spell check a box...
VB Code:
Public Function CheckSpelling(t As TextBox)
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim strResult As String
'Create a new instance of word Application
If (Len(t.Text) = 0) Then
'nahhhhhhhhhhh
Else
Set objWord = CreateObject("word.Application")
Select Case objWord.Version
'Office 2000, xp, 2k3
Case "9.0", "10.0", "11.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office 97
Case Else
Set objDoc = objWord.Documents.Add
End Select
objDoc.Content = t.Text
objDoc.CheckSpelling
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
If t.Text = strResult Then
' There were no spelling errors, so give the user a
' visual signal that something happened
MsgBox "The spelling check is complete.", vbInformation + vbOKOnly, "Spelling Complete"
End If
'Clean up
objDoc.Close False
Set objDoc = Nothing
objWord.Application.Quit True
Set objWord = Nothing
' Replace the selected text with the corrected text. It's important that
' this be done after the "Clean Up" because otherwise there are problems
' with the screen not repainting
t.Text = strResult
End If
Done:
Exit Function
'in case user does not have word...
Err_Handler:
MsgBox Err.description & Chr(13) & Chr(13) & "Please note you must have Microsoft Word installed to utilize the spell check feature.", vbCritical, "Error #: " & Err.Number
Resume Done
End Function
But I want to call it and pass the text box that has the focus via say F7 key click. Right now Im not sure how to do this though
Anyone with some ideas?
-
Jul 2nd, 2004, 02:24 PM
#3
Thread Starter
Banned
Err...
So I can loop through the controls to find the text box...
but I need to be able to have an AND condition in the if to see if the text box has focus.
I only want to spell check the textbox that has the focus ONLY!!!
VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Err_Handler
Dim ctl As Control
If KeyCode = vbKeyF7 Then
'let's check each control
For Each ctl In Me.Controls
'is it a button
If TypeOf ctl Is TextBox Then
Call CheckSpelling(ctl)
Exit For
End If
Next ctl
Else
'do nothing
End If
Done:
Exit Sub
Err_Handler:
MsgBox Err.description, vbCritical, "Error #: " & Err.Number
Resume Done
End Sub
...Need to modify
if TypeOf ctl is TextBox AND hasfocus!!!
Any ideas ?
-
Jul 2nd, 2004, 02:26 PM
#4
Have you tried form.activecontrol??
-
Jul 2nd, 2004, 02:35 PM
#5
Thread Starter
Banned
Originally posted by szlamany
Have you tried form.activecontrol??
Me no like that..but it may be me only option
Shanks,
-
Jul 2nd, 2004, 03:05 PM
#6
Originally posted by jhermiz
Me no like that....
Why not? It's a legitimate part of the language.
-
Jul 2nd, 2004, 03:06 PM
#7
Thread Starter
Banned
Originally posted by MartinLiss
Why not? It's a legitimate part of the language.
My mistake..
I was using the formName.ActiveControl and thought I'd have to do that for each form...then I realized you can use Me.
Works fine..see my post in your spell checker.
Jon
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|