Results 1 to 6 of 6
  1. #1
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78

    Required field causing error message when not populated

    Hello, let me preface this by saying that nothing I've tried is working even though it's straight out of positive forum results!

    My database has a field that is set to Required in the table (tblrequests) design.

    I'm using this field on a form that is using tblrequests, I've tried different things to make the error message not show up but it does, including making the field not required.

    The error is "Run-time error '3314' You must enter a value in the tblRequests.txtProjectNumber' field"

    I tried making it not required and instead put the following code in the BeforeInsert or BeforeUpdate but it's not working either.

    If Me.txtProjectNumber & ""<> """" Then
    MsgBox "Project # is required....etc",vbOKOnly
    End if



    Also
    If Me.txtProjectNumber & "" Then
    MsgBox "Project # is required....etc",vbOKOnly
    End if


    My "OnClick" code is:

    bSave = True
    If Me.Dirty Then
    M.Dirty = False
    End If

    DoCmd.OpenReport "rptViewEst", acViewReport, "", "txtProjectNumber=Forms!frmRequests!txtProjectNumb er", acNormal

    Any thoughts?

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

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Shouldn't first test be = and not <> ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    If the control is left empty it will be Null not "", so Me.txtProjectNumber & "" will not be equal to """" .
    You should try
    Code:
    Nz(Me.txtProjectNumber,"") & "" =  """" 
    or easier
    Code:
    If IsNull(Me.txtProjectNumber) then Msgbox "The Project Number is required"
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    Thank you Vlad, your suggestion worked. I changed it a little bit to suit my requirements but this was spot on!

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 2
    Last Post: 06-02-2015, 12:32 PM
  2. Replies: 5
    Last Post: 05-15-2015, 10:49 AM
  3. Replies: 3
    Last Post: 05-12-2015, 03:43 PM
  4. Replies: 2
    Last Post: 02-14-2014, 04:05 PM
  5. Replies: 11
    Last Post: 08-25-2012, 12:36 PM

Tags for this Thread

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