Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting SetFocus after After_Update() event

Status
Not open for further replies.

jambai

Programmer
Mar 21, 2007
58
US

After the validation the focus was not set to the particular control.
It moves to the next control.

Please let me know who to set focus after AfterUpdate event.

Private Sub txtName_AfterUpdate()
If Not IsNull(Me.txtName.Value) Then
MsgBox ("Not Null")
Else
MsgBox "Enter Name!", vbInformation
Me.txtName.SetFocus
End If
End Sub

Thanks
Jambai
 
It would be best to use the Before Update event with Cancel, if the control does not validate.
 
Private Sub txtName_[!]Before[/!]Update([!]Cancel As Integer[/!])
If Trim(Me!txtName.Value & "") = "" Then
MsgBox "Enter Name!", vbInformation
Cancel = True
End If
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
or to check for null and an empty string:
Code:
[blue]   If IsNull(Me![purple][b][i]txtName[/i][/b][/purple],"") = "" Then
      MsgBox "Enter Name!", vbInformation
      Cancel = True
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
I can't do the requery in this event.

Actually my original good looks like

If Not IsNull(Me.txtDefNameSearch.Value) Then
Dim strChkDef As String
Dim rsChkDef As DAO.Recordset
strChkDef = "SELECT * FROM dbo_DEFEND WHERE NAME='" & txtDefNameSearch & "';"
Set rsChkDef = CurrentDb.OpenRecordset(strChkDef, dbOpenDynaset, dbSeeChanges)

If rsChkDef.RecordCount > 0 Then
Me.cmdAddDef.Visible = False
Me.cmdSaveDef.Visible = True
Forms!frmDefendant.Requery
Else
MsgBox "DEFENDANT NOT FOUND!", vbInformation
Me.txtDefNameSearch.SetFocus
Me.cmdAddDef.Visible = True
Me.cmdSaveDef.Visible = False
End If
End If

Thanks
Jambai
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top