Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2002
    Posts
    173

    Unanswered: required form field

    I have a male/female drop down field that I'd like to make required by adding code to the form and not the design of the table. How can I stop the user from closing the form if this field is blank?

  2. #2
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Form unload event

    Private Sub Form_Unload(Cancel As Integer)


    if is null (me.nameofyourfield) then

    Msgbox "Please select gender...", vbokonly, "Gender field is required:"
    cancel = true
    me.nameofyourfield.setfocus

    end if

    end sub


    ...should work
    Last edited by garethdart; 03-04-03 at 11:41.

  3. #3
    Join Date
    Jun 2002
    Posts
    173
    I got it going almost 100% now. When the close button is pushed the message comes up as it should. But then I get a "Close Action Was Cancelled". Is there a way to get rid of this?

  4. #4
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    yep

    docmd.setwarnings false

    to reset

    docmd.setwarnings false

    also, if you have record nav on form need to test user doesnt type erroneous data, move to next record then close

    If you havent, dont worry
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  5. #5
    Join Date
    Jun 2002
    Posts
    173
    everything is working great now except when a record is deleted the form cannot be closed because it prompts for the gender. is there anyway around this one? thanks for all the help!

  6. #6
    Join Date
    Jun 2002
    Posts
    173
    I tried adding the extra if statement to only check for gender if the lastname has data entered. I thought this would be a good way around the deleted record still checking on gender. This is the code I'm trying to work out but when I added the "If (Me.Emp_LastName) <> Null Then" it seems to completely ignore the gender field if there's data in the last name field or there isn't.


    If (Me.Emp_LastName) <> Null Then
    If IsNull(Me.Emp_Sex) Then
    MsgBox "Please select gender...", vbOKOnly, "Gender field is required:"
    Cancel = True
    Me.Emp_Sex.SetFocus
    End If
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •