Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2012

    Unanswered: Display message if a field is empty


    I would like to check a field to see if its empty when closing down a form. If it is empty I would like a message box displayed. I have this code on the beforeupdate event but get no box displayed.

    Private Sub Form_BeforeUpdate()

    Dim Msg, Style, Title, Help, Ctxt, Response, MyString

    Msg = "Customer field cannot be empty"
    Style = vbYesNo + vbCritical + vbDefaultButton2
    Title = "MsgBox"
    Help = "DEMO.HLP"
    Ctxt = 1000

    If Me.Customer = "" Then

    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then
    MyString = "Yes"
    Else ' User chose No.
    MyString = "No"
    End If

    End If

    End Sub

    I suspect there maybe an easier way to do this and I maybe over complicating things.

    Any advice appreciated.


  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    I suspect your code is in the wrong place
    do you mean validate a control has valid data before saving. if so consider placing your validation code in the form (or controls) before update event
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2012
    Thanks for the reply.

    Its quite a basic DB, I have a form that displays data in a table, if a user changes a field to out or permanent I want to make sure the Customer field has data in it so we know where an item has gone to. I take it the me.customer part would check the current record ?

    I have the code placed in

    Private Sub Form_BeforeUpdate()



Posting Permissions

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