Results 1 to 10 of 10
  1. #1
    a.phoenix is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Oct 2017
    Posts
    17

    Setup field required in the forms

    I need to set required some field in the forms. I know I can do it in the property of table, but that field will affect to another from too.




    So, can I use the macros or modules to fix it?


    Please, tell me how to do it. I don't have so much experience with macro and modules.


    Thank you
    Prakan.P

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,943
    Most people would put a value in the Tag property of the controls, let's say R, and then check for that tag and whether that control has a value and is valid.

    https://www.google.com/search?q=acce...hrome&ie=UTF-8
    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

  3. #3
    Edgar is online now Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Validate your form entries with the BeforeUpdate event of the form if you're editing a record and BeforeInsert if you're adding a new record. Do you know how to do that?

  4. #4
    a.phoenix is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Oct 2017
    Posts
    17
    Thanks for your answer.

    Absolutely Not, I know the basics of access to create the table, forms, report command and little about macros.

    and if it not so much I wonder if I set the table to required = Yes, can I use macros or modules for the massage warning example

    I have field status and in property of this field in the table I choose required = Yes. I found the error warning is not friendly to user understanding. If I want to change warning like "please choose the status" how to do it?

  5. #5
    a.phoenix is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Oct 2017
    Posts
    17
    Thanks for your answer.

  6. #6
    a.phoenix is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Oct 2017
    Posts
    17
    Quote Originally Posted by Edgar View Post
    Validate your form entries with the BeforeUpdate event of the form if you're editing a record and BeforeInsert if you're adding a new record. Do you know how to do that?
    Thanks for your answer.

    Absolutely Not, I know the basics of access to create the table, forms, report command and little about macros.

    and if it not so much I wonder if I set the table to required = Yes, can I use macros or modules for the massage warning example

    I have field status and in property of this field in the table I choose required = Yes. I found the error warning is not friendly to user understanding. If I want to change warning like "please choose the status" how to do it?

  7. #7
    Edgar is online now Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Add this to your form's code
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        If IsNull(Me.status) Then
            Cancel = True
            MsgBox "Please choose the status"
        End If
    End Sub
    Change me.status with the name of the control you want to make sure has been filled.

    As for your table field being required, that's up to you, I don't remember if you can modify the message. With this form code, the user won't be able to add or modify records if that control is empty, additionally, you can customize the message.

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    If there are more than 3 controls I'd probably use the tag approach mentioned in post 2 rather than have a sub for every one of them since the number of controls needing this sometimes grows as things change. The worst part of the multi sub approach is that one usually codes to exit if a required field has no value. User fixes that and tries to save again only to encounter another annoying prompt. I avoid that by listing all of them at once in one message box. I also like to ensure that the labels for these controls are attached. That way, I can get the descriptive text for the field (e.g. First Name) from the label rather than the name of the control (e.g. txtFName). However, I would have that situation because I never allow a field and control to have the same name, and the field names are often shortened since they only need to make sense to me.

    @a.phoenix, if you want some code that handles all this, I should be able to find it in my archives. You would need to add a tag - e.g. Reqd (no quotes) to the tag property for those controls that require this validation. Also best to limit the search in the code to only the type(s) of controls you've done this for so you'd need to define that in a post.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi
    The attached gives some examples of using the Tag
    Attached Files Attached Files
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  10. #10
    a.phoenix is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Oct 2017
    Posts
    17
    Thanks you very much.

    Quote Originally Posted by Edgar View Post
    Add this to your form's code
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        If IsNull(Me.status) Then
            Cancel = True
            MsgBox "Please choose the status"
        End If
    End Sub
    Change me.status with the name of the control you want to make sure has been filled.

    As for your table field being required, that's up to you, I don't remember if you can modify the message. With this form code, the user won't be able to add or modify records if that control is empty, additionally, you can customize the message.

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

Similar Threads

  1. Replies: 10
    Last Post: 06-18-2015, 11:52 AM
  2. Setup a field to Total Weight in My Report
    By Triland in forum Access
    Replies: 2
    Last Post: 01-25-2013, 02:11 PM
  3. Replies: 1
    Last Post: 12-07-2012, 02:14 AM
  4. Replies: 7
    Last Post: 10-04-2012, 01:21 PM
  5. Forms help required
    By martin james in forum Access
    Replies: 5
    Last Post: 12-16-2011, 10:18 AM

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