LostFocus

  • Thread starter Thread starter Elwin
  • Start date Start date
E

Elwin

Use the BeforeUpdate() event of the control to validate it.

Private Sub IPByte3_BeforeUpdate(Cancel As Integer)
Dim Ok As Integer
If Me!IPByte3 = "" Then
Ok = MsgBox("Missing IP byte. Re-enter?", _
vbYesNo + vbExclamation, "Missing Byte")
If Ok = vbYes Then
Cancel = True
Else
cmdClear_Click
End If
End If
End Sub

Use the AfterUpdate() event of the control to set other
values.

Private Sub IPByte3_AfterUpdate()
IPRange.Value = IPRange.Value & IPByte3.Value & "."
End Sub

I don't know what the cmdClear_Click event is doing, so
you may need to call it from somewhere else if it alters
the contents of the IPByte3 control in any way. I'm
hoping that cancelling the BeforeUpdate event will
eliminate the need to call it. Good luck.
 
Thank you for your help.

Here is the order:
There are 4 boxes, for IP address bytes, the event below,
for byte #3, is supposed to check for data on exit in the
byte3 text box. If there is none, then I would like the
cursor to stay on byte3 text box. Instead, it goes to
byte4.

Private Sub IPByte3_LostFocus()

Dim Ok As Integer

If IsNull(IPByte3.Value) Then
Ok = MsgBox("Missing IP byte. Do you want to re-enter
it?", vbYesNo + vbExclamation, "Missing Byte")
If Ok = vbYes Then
DoCmd.CancelEvent
IPByte3.SetFocus
Else
cmdClear_Click
End If
Else
IPRange.Value = IPRange.Value & IPByte3.Value & "."
End If
End Sub
 
This works... Thanks

Private Sub IPByte4_Exit(Cancel As Integer)

If IsNull(IPByte4.Value) Then
MsgBox "Missing IP byte. Please re-enter.", vbOKOnly
+ vbExclamation, "Missing Byte"
DoCmd.CancelEvent
Else
IPRange.Value = IPRange.Value & IPByte4.Value
End If

End Sub
 
Back
Top