• Required Field

    Author
    Topic
    #356885

    I have a form where I need to make sure a field is not blank. The field on the form is SpecID which has a dropdown list to select initials of the person. I created a table of initials with SpecID as the Primary key. I used this key in another table and used the Lookup wizard to make a combo box of initials. Now on the form I want to make sure the people select their initials. I have tried making it a required field in the table and I have tried creating a macro that says if SpecID is Null – cancel event – display message and Gotocontrol. That doesn’t work either. Is there any way to make sure this field is not blank????

    Viewing 0 reply threads
    Author
    Replies
    • #529039

      If you’ve made the field Required in your table, then you should not be able to move off the record (which causes an immediate update for a bound form) if nothing has been selected. Are you trying to prevent them from leaving that field without making a selection? I would advise against that. You can also put in code in your form’s BeforeUpdate event. Check that field for IsNull, if true, then set “Cancel=True” and “Exit Sub”.

      • #529041

        I attached the macro to the BeforeUpdate event of the form. When I test the field by leaving it blank, it lets me create a record even though that field is blank. I even have it as a required field in the table but I leave it blank and it lets the record go through. Does it have something to do with the fact that I used a wizard to create the dropdown list?

        • #529101

          There is a difference between blank and null (no entry). Check your field properties in your table, and make sure the Allow Zero Byte string is set to False (and required is set to True). Also, you combo box can be set to “LimitToList=True”.

        • #529801

          Linda,

          It shouldn’t have anything to do with the wizard. I first thought, using a macro and not an event procedure for the BeforeUpdate event could be the culprit (I never use macros for events). Now I just tested such a macro and it works. It doesn’t let me save the record even if the table field is not required and the NotInList procedure is not bothering. So it must be something else. Are you sure you can save records with that field empty after editing? Existing records with SpecID empty will remain so if there is no change in the record, because neither form’s BeforeUpdate nor ctlSpecID’s NotInList fires then.

          Maybe you can post your macro commands here in some form, although an event procedure would be much better.

          BTW, LimitToList=True itself does allow an empty field in A97 and A2K. But you should set it anyway, otherwise the users could enter initials not contained in your table.

    Viewing 0 reply threads
    Reply To: Required Field

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: