Results 1 to 8 of 8
  1. #1
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102

    In a form 1 of 2 fields must be filled.

    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?

  2. #2
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Use the BeforeUpdate event of the form to validate the entry and Cancel if both are empty:
    Code:
    If IsNull(Me.textbox1) And IsNull(Me.textbox2) Then Cancel=True
    https://docs.microsoft.com/en-us/off...reupdate-event
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    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.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102
    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.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    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
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102
    Thank you, it worked.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    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
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Automatic flag when fields are filled
    By NicoCaldo in forum Access
    Replies: 3
    Last Post: 12-15-2017, 03:52 AM
  2. Replies: 3
    Last Post: 01-12-2014, 02:34 AM
  3. Replies: 8
    Last Post: 08-02-2012, 02:53 PM
  4. How do I see only fields that are filled?
    By fabiobarreto10 in forum Forms
    Replies: 56
    Last Post: 01-01-2012, 09:51 PM
  5. query with fields that cannot be filled in
    By durstlaw in forum Queries
    Replies: 3
    Last Post: 07-23-2010, 12:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums