Hi All,
I have a simple search form that has a two text boxes and two search buttons. One of the search buttons and text boxes is as below:
txtPayrollIDSearch and cmdPayrollIDSearch
I have the following code for the search button:
When the button is clicked it will bring up a message box if the text box is empty, if it's not then it will open frmUser, edit the caption of the header in the form, disable a couple of fields and set the focus to the Forename field.
What I want to be able to do is rather than having to click the button, I want to just type in my search criteria and press the Enter key. Currently, I have to press enter twice... Once to set focus to the button and then the second time launches the code.
I've tried setting the above code to On Focus too, but I am trapped on the Forename field and can't close down the form.
I can also assign the same code to the On Exit event for either text box but if I click into one and do not type anything into it and click into the other search button (because I've changed my mind and want to use the other search criteria) it brings up my message box which is a little irritating.
How do I solve this conundrum?
Many thanks
EDIT: Solved: Use After Update.
I have a simple search form that has a two text boxes and two search buttons. One of the search buttons and text boxes is as below:
txtPayrollIDSearch and cmdPayrollIDSearch
I have the following code for the search button:
Code:
Private Sub cmdPayrollIDSearch_Click()
If IsNull(Me.txtPayrollIDSearch.Value) Then
MsgBox "Please enter a value", 48, "Unable to search!"
Else
Dim sWHERE As String
sWHERE = "[PayrollID] = " & Me.txtPayrollIDSearch
sWHERE = "[PayrollID] = '" & Me.txtPayrollIDSearch & "'"
DoCmd.OpenForm "frmUser", acNormal, , sWHERE, acFormEdit
Forms!frmUser.Header0.Caption = "Edit User"
Forms!frmUser.txtPayrollID.Enabled = False
Forms!frmUser.txtForename.Enabled = False
Forms!frmUser.txtSurname.SetFocus
End If
End Sub
When the button is clicked it will bring up a message box if the text box is empty, if it's not then it will open frmUser, edit the caption of the header in the form, disable a couple of fields and set the focus to the Forename field.
What I want to be able to do is rather than having to click the button, I want to just type in my search criteria and press the Enter key. Currently, I have to press enter twice... Once to set focus to the button and then the second time launches the code.
I've tried setting the above code to On Focus too, but I am trapped on the Forename field and can't close down the form.
I can also assign the same code to the On Exit event for either text box but if I click into one and do not type anything into it and click into the other search button (because I've changed my mind and want to use the other search criteria) it brings up my message box which is a little irritating.
How do I solve this conundrum?
Many thanks
EDIT: Solved: Use After Update.
Last edited: