Popup message if record not updated

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

I have a form with a subform that requests users to input data via drop-down
boxes and text boxes.

However, if none of these boxes are updated, I would like a pop-up message
to appear asking the user to fill out at least one of the boxes. Or if they
don't know, to select don't know from the last tab called, "Feedback" on my
subform. Until something is filled out or "I don't know" is selected, the
user should not be able to access the next record.

How would I do that? Thanks in advance for your help.

Matt
 
You'd need to put code in the BeforeUpdate event of the form being used as a
subform.
 
Hi Doug,

What kind of code would I need? I'm not very good at writing code so any
suggestions would be very helpful. Thanks.
 
Something like

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If Len(Me!Text0 & vbNullString) = 0 And _
Len(Me!Text1 & vbNullString) = 0 And _
Len(Me!Text2 & vbNullString) = 0 Then

MsgBox "You must enter something into at least one control"
Cancel = True

End If

End Sub
 
Douglas J. Steele said:
Something like

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If Len(Me!Text0 & vbNullString) = 0 And _
Len(Me!Text1 & vbNullString) = 0 And _
Len(Me!Text2 & vbNullString) = 0 Then

MsgBox "You must enter something into at least one control"
Cancel = True

End If

End Sub
<snip>

Doug

Your code as it stands requires that the user fill all the textboxes, not
'at least one'.

David:

It isn't too clear from your post whether all the textboxes should be filled
in order to trigger the msgbox. If that is indeed the case, then Doug's code
is correct. If not, simply change the And's to Or's:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If Len(Me!Text0 & vbNullString) = 0 Or _
Len(Me!Text1 & vbNullString) = 0 Or _
Len(Me!Text2 & vbNullString) = 0 Then

MsgBox "You must enter something into at least one control"
Cancel = True

End If

End Sub
 
Back
Top