Your code:
Code:
Private Sub CmdBtnClrSelection_Click()
Dim Ctl As Control
For Each Ctl In Me.Controls '<<-- Loops through EVERY control on the form
If Ctl.ControlType = acTextBox Then '<<-- checks to see if control is a text box
If Ctl.Value <> True Then '<<-- is the value of the control Not True? (doesn't really make sense)
Ctl.Value = False '<<-- set the control value to FALSE (ie 0)
Else
If Ctl.Value <> False Then '<<-- is the value of the control Not False? (doesn't really make sense
Screen.ActiveControl = "" '<<-- set the control value to an empty string
End If
End If
End If
Next Ctl
End Sub
Once you click the button, the button becomes the ActiveControl and you don't know what the previous control was.
Try this:
Code:
Private Sub CmdBtnClrSelection_Click()
Dim Ctl As Control
' MsgBox Screen.PreviousControl.Name
Set Ctl = Screen.PreviousControl '<<-- get the previous control
If Ctl.ControlType = acTextBox Then '<<-- ensure that the control is a text box
Ctl = vbNullString '<<--set the control value to a NULL string. "VALUE" is the default property, so you don't need to specify it.
End If
'clean up
Set Ctl = Nothing
End Sub