Textbox gotfocus after search

Lifeseeker

Registered User.
Local time
Today, 14:26
Joined
Mar 18, 2011
Messages
273
Hi,

I have a form on which there is a textbox control that I would like to add a bit more security.

There is a search button on the form and when it is clicked, users will be able to search the record based on the textbox.

When a user cancels out of the search box, the cursor focus is now back in the textbox field. I fear that if a user accidently hits ECS, that will wipe out the content of the textbox, which is the PK.

So is there a way around it so that after the search box has been cancelled, the cursor is focused on a different textbox that is of no significance?


Many thanks on this.
 
Why search the record via the text box? If it is the PK then there should only be one record in the form's recordset which matches and you would be on it to be able to search based on it.

Put an unbound combo box on the form (in fact, if you use the wizard it will actually give you a third option which is find a record) and then let them use that to search and not mess with any fields.

If you simply do not want to do that then I would set the form's text boxes' locked property to yes in the form's On Current event and have a button you can push to go into edit mode where you unlock them. You can lock and unlock by putting this into a standard module and then call it from the form's On Current event to lock or the button's click event to unlock:

Code:
Function LockUnlockTextBoxes(strForm As String, blnLock As Boolean)
   Dim ctl As Control
 
For Each ctl In Forms(strForm).Controls
   If ctl.ControlType = acTextBox Then
      ctl.Locked = blnLock
   End If
Next
End Function

Then in the form's On Current event you can use

LockUnlockTextBoxes Me, True

to lock

and in the button's click event to unlock

LockUnlockTextBoxes Me, False
 
Why search the record via the text box? If it is the PK then there should only be one record in the form's recordset which matches and you would be on it to be able to search based on it.

Put an unbound combo box on the form (in fact, if you use the wizard it will actually give you a third option which is find a record) and then let them use that to search and not mess with any fields.

If you simply do not want to do that then I would set the form's text boxes' locked property to yes in the form's On Current event and have a button you can push to go into edit mode where you unlock them. You can lock and unlock by putting this into a standard module and then call it from the form's On Current event to lock or the button's click event to unlock:

Code:
Function LockUnlockTextBoxes(strForm As String, blnLock As Boolean)
   Dim ctl As Control
 
For Each ctl In Forms(strForm).Controls
   If ctl.ControlType = acTextBox Then
      ctl.Locked = blnLock
   End If
Next
End Function

Then in the form's On Current event you can use

LockUnlockTextBoxes Me, True

to lock

and in the button's click event to unlock

LockUnlockTextBoxes Me, False


Thanks for posting back.

I've thought about it and maybe it's even easier to just put a lock on that particular textbox.(fee_num)

I've also realized that you can simply change the control's locked property into "yes", but I'm just curious to see the code that actually does that.

The following code didn't run in VBA.

Me.fee_num.locked = true

Thanks
 
Is the control's name actually fee_num? I ask because

Me.fee_num.locked = true

is valid code, assuming the control name is correct.

Where did you place this code?

If your only concern is the accidental deleting of the textbox value, because it is hilighted when it gets focus, then simply don't let the text be selected:
Code:
Private Sub SearchString_Enter()
  Me.SearchString.SelStart = 0
  Me.SearchString.SelLength = 0
End Sub
Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom