Control not in active window

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I keep getting an error Control not in active window with a form keypress event. I refer to me.activecontrol.value to set a control's value. I have the key preview set to True and cannot refer to the control directly because I have many control's values to set and want the sub to be global for the form. What should I do so I can refer to the activecontrol's value from a form? Thanks.
 
Show us the code.

TC


Mike said:
I keep getting an error Control not in active window with a form keypress
event. I refer to me.activecontrol.value to set a control's value. I have
the key preview set to True and cannot refer to the control directly because
I have many control's values to set and want the sub to be global for the
form. What should I do so I can refer to the activecontrol's value from a
form? Thanks.
 
This is the code. I have textboxes named T1 thru T100. I want a user to be able to be in any textbox, hit CTL+A (or S,etc.) and place the number 1 (or 2, etc) into the active textbox (say T3) and the next two (i.e., T4 and T5). That's why I put the Keypress event on the form rather than on the textbox -- I'd have to write it 100 times. Is there a better idea of how to do it? Thanks,

Private Sub Form_KeyPress(KeyAscii As Integer)
Dim contrl_c As String
Dim i As Integer
Dim frm As Form
Dim ctl As Control
Set ctl = Screen.ActiveForm
For i = 1 To 3
Me.ActiveControl = Chr(KeyAscii)
contrl_c = "T" + LTrim(Str(Me.ActiveControl.TabIndex + 1))
DoCmd.GoToControl contrl_c
Next
End Sub
 
Ok. The user is in a textbox. He hits CTRL-A (or whatever). What happens
then? What is "the number" that gets copied into the current & next
controls? Is that the CTRL-A, or is it something else?

As for your code, it seems to wait for >any< keypress (of any description),
then tries to copy that key into the current control & the two after it.
That would make the form almost inoperable, in my opinion. Is that really
what you want it to do? If so, what is the purpose or benefit of doing that?

HTH,
TC



Mike said:
This is the code. I have textboxes named T1 thru T100. I want a user to
be able to be in any textbox, hit CTL+A (or S,etc.) and place the number 1
(or 2, etc) into the active textbox (say T3) and the next two (i.e., T4 and
T5). That's why I put the Keypress event on the form rather than on the
textbox -- I'd have to write it 100 times. Is there a better idea of how to
do it? Thanks,
 
Back
Top