Results 1 to 2 of 2
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Thanked 0 Times in 0 Posts

    Required field (2003)

    I have a form that has two txt fields. Both fields need to be filled in. Once fields are filled in, they click on a command button to preview a report. I tried the following code but it doesn't work. The first text field in entered but the second one is not. I click on run the report and the message does not appear and the report runs and brings back errors. Is there something I am missing? Thanks for your help....
    Private Sub Form_BeforeUpdate(Cancel As Integer)

    If IsNull(Me.txtempid) Then
    MsgBox "You must enter employee number!", vbExclamation
    Cancel = True
    End If
    End Sub

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Crystal Beach, FL, Florida, USA
    Thanked 41 Times in 40 Posts

    Re: Required field (2003)

    You have 2 problems here.

    First of all, your BeforeUpdate event seems only to be checking for one field.

    Secondly (and this is a guess), unless your Report button tries to save the current record, the BeforeUpdate Event won't be run. Your code in this report button should be something like this:

    Dim Cancel as Integer

    If me.dirty = true then
    form_BeforeUpdate Cancel
    If Cancel = False then
    Exit sub
    end if
    Runcommand accmdSaveRecord
    End If
    Docmd.OpenReport "yourReport"
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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