Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2009
    Posts
    10

    Unanswered: Trying to require data on form during update.

    I have a form that has data and some blank fields. There is a date of birth field that must be updated. I am using the set focus to activate the field and lost focus to make sure a date is entered. If not I want to set the focus back to the field. Here is the code I am trying. It displays the msg but allways goes to the next field.

    ____
    Private Sub Birthdate_LostFocus()
    On Error GoTo Err_Birthdate_LostFocus

    xdob = [Birthdate] & ""
    If [xdob] = "" Then
    strMsg = "You must enter a date of birth!"
    MsgBox strMsg, vbExclamation, "Error"
    Me.Birthdate.SetFocus

    Else

    End If
    Exit_Birthdate_LostFocus:
    Exit Sub
    Err_Birthdate_LostFocus:
    MsgBox Err.Description
    Resume Exit_Birthdate_LostFocus

    End Sub
    _____

  2. #2
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    Use the BeforeExit event. That has an argument called Cancel that allows you to explicitly prevent the focus from leaving the control.
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  3. #3
    Join Date
    Oct 2009
    Posts
    10
    I am using Access 03 and dont see a BeforeExit event.
    Just cant figure out how to get focus to stay on the field.
    I know i could put a check for the value in the next field but the next field that would be used is a set of 10 check boxes. so i would have to repeat the check before entering each of them, doable but I was looking for a cleaner way.

  4. #4
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    Apologies - I conflated two different ones. You can either try the BeforeUpdate event or the Exit event. Both of these have a Cancel argument that, if set to True, prevents the focus from leaving the control.
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  5. #5
    Join Date
    Oct 2009
    Posts
    10

    Thumbs up

    That worked perfectly! Caused a new problem but worked perfectly!!
    I now must change my msg box to a OK/Cancel so that if they dont have a birthdate for that person they have a way out.

    Again Thanks!

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    lol

    So the field isn't required after all?! I wouldn't bother annoying the user with useless messages then.

    Think about it.

    System says: YOU MUST FILL IN A BIRTHDATE... unless you click CANCEL. Sorry, but that is just dumb.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  7. #7
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    Rather than have blank fields, use the message box to assign a nonsensical DoB value (e.g. 01/01/1900). Then the user has a choice between finding the correct DoB now or using the default.

    You could then create a report to find all records with the default values and chase the data entry people to put the correct values in later.
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  8. #8
    Join Date
    Oct 2009
    Posts
    10

    Reasoning

    So the answer is the birthdate is required to evaluate adult or pediatric dose for a medication. The database gets DOB for 98% of the people (roughly). I built a drop down list that only has those with no DOB. The goal is to have the person doing the entry look in another computer system and get birth dates for these people.

    If they use the drop down list and look the person up and still cant find a DOB they needed a way to cancel out and select the next person.

    So yes it is required but may not be available. And I cant put in a nonesense value because I dont want to calculate an age based on bad information.

    The good news is that with the information given I was able to make this work and the people using the system like the interface!

Posting Permissions

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