My Assistant
![]()
Custom Search
|
![]() ![]() |
![]() |
![]() Post#1 | |
![]() Posts: 434 Joined: 12-February 14 ![]() | Hi all, I have a subform with datasheet view with a combo and a date text box for each record. I want to not allow the user to go to the next record if only combobox is filled or the Date text box is filled. I tried this but it is not working: CODE Private Sub DateDispo_LostFocus() On Error GoTo DateDispo_LostFocus If IsNull(Me.DispoID) Then Cancel = True Else MsgBox "Please fill in the Dispo Date field!" Me.DispoID.SetFocus Me.DateDispo.SetFocus End If Exit_DateDispo_LostFocus: Exit Sub DateDispo_LostFocus: MsgBox "There has been an Error. The Error number is: " & Err.Number & vbCrLf & "The Error Description: " & Err.Description Resume Exit_DateDispo_LostFocus: End Sub Thank you |
![]() Post#2 | |
![]() UA Moderator Posts: 76,880 Joined: 19-June 07 From: SunnySandyEggo ![]() | I would try using the Form's BeforeUpdate event. Hope it helps... |
![]() Post#3 | |
![]() Posts: 434 Joined: 12-February 14 ![]() | theDBguy, Thank you. I think I came up with the solution!? Any comments? CODE Private Sub Form_BeforeUpdate(Cancel As Integer) If Not IsNull(Me.DispoID) And IsNull(Me.DispoDate) Then MsgBox "Date must be filled" Cancel = True ElseIf IsNull(Me.DispoID) And Not IsNull(Me.DispoDate) Then MsgBox "Dispo must be selected" Cancel = True Else End Sub Thank you |
![]() Post#4 | |
![]() UA Moderator Posts: 76,880 Joined: 19-June 07 From: SunnySandyEggo ![]() | Hi. Glad to hear you got it working. |
![]() Post#5 | |
Posts: 7,115 Joined: 22-December 10 From: England ![]() | Based on the code you've posted I would change the "Else" to "End IF" |
![]()
Custom Search
|
![]() | Search Top Lo-Fi | 12th December 2019 - 12:46 AM |