Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2013
    Posts
    22

    Unanswered: How to make a field mandatory based on another field before saving

    Hey all!
    I have created a form where I have bunch of inputs which I am taking from a user, however when one activity is selected from a combobox, I am sending the user the description field where they need to provide a description. Till here I am fine and dandy! But when I am saving the record, I basically want to make sure the same conditions as mentioned above are satisfied and the description field is populated when a certain value from an activity value in a combobox.

    Here is the code that I have written as of yet: but it is just doing the check once and then saves my record! Please help!

    Code:
    xx: If Activities.Value = "- One Off Requests" And Desp1.Value = "" Then
        Desp1.SetFocus
            If Desp1.Value = "" Then
                Response = MsgBox(Prompt:="Please provide name of the requestor and the naure of the request", Buttons:=vbYesNo)
                If Response = vbYes Then
                    Desp1.SetFocus
                Else
                    MsgBox "You are need to provide the information of one off request. Please fill out the detials.", vbCritical
                    GoTo xx:
                End If
            End If
    End If

  2. #2
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    Move the code to the BeforeExit event of Desp1, and remove the label. Replace the GoTo command with Cancel = True, Exit Sub (each on its own line).

    See if that helps!
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  3. #3
    Join Date
    Jan 2013
    Posts
    22
    Hey thanks for the suggestion, do you mean BeforeUpdate event or OnExit, cause i can not find BeforeExit event...

    Quick Update!

    I figured it out! and it worked like charm! thank you Weejas!
    Last edited by nbkn8ct; 01-03-13 at 13:58.

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I personally would use the before update event of the form:

    Before update

    The problem with a particular control's exit event is that the user might mouse over it and the event will never fire.
    Paul

  5. #5
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    D'oh! This is what I get for reading an Access forum as a break from programming in Notes... Yes, I meant the BeforeUpdate event, and I'm glad you managed to sort it out
    10% of magic is knowing something that no-one else does. The rest is misdirection.

Posting Permissions

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