Hello everyone,
I have a form in which there are 2 text fields(textfield 1 and textfield 2). I want the user to write something in at least one of them. How do I do this?
Hello everyone,
I have a form in which there are 2 text fields(textfield 1 and textfield 2). I want the user to write something in at least one of them. How do I do this?
Use the BeforeUpdate event of the form to validate the entry and Cancel if both are empty:
https://docs.microsoft.com/en-us/off...reupdate-eventCode:If IsNull(Me.textbox1) And IsNull(Me.textbox2) Then Cancel=True
Cheers,
I'd use the before update event of the form:
http://www.baldyweb.com/BeforeUpdate.htm
You would test to see if they're both empty.
What would the Code look like then?
Mine looks like this right now:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.MonatslohnBrutto) And IsNull(Me.StundenlohnBrutto) Then Cancel = True
MsgBox "You must enter a value for monthly or hourly wage!"
End Sub
But the MsgBox is called although a value is filled in one of the 2 fields.
You've used the one-line format of the If/Then, so the next line will run no matter the result. Try
Code:If IsNull(Me.MonatslohnBrutto) And IsNull(Me.StundenlohnBrutto) Then Cancel = True MsgBox "You must enter a value for monthly or hourly wage!" End If
Thank you, it worked.
Or if you want to stick to one line:
Code:If IsNull(Me.MonatslohnBrutto) And IsNull(Me.StundenlohnBrutto) Then MsgBox "You must enter a value for monthly or hourly wage!":Cancel = True