Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If..Then null (2002)

    I am trying to write an IF..Then code that will make a message appear if a textbox is not filled in or empty or save the file if the textbox has data in it. Below is what I was started out with and then got stuck. Can anyone help. Thanks Paul

    If Me.Class = "" Then
    MsgBox "You must enter this student's graduation year.", vbOKOnly
    Me.Class.SetFocus
    Else

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    DoCmd.GoToRecord , , acNewRec
    Me.txtname.SetFocus

    End If

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If..Then null (2002)

    There is usually no need to save a record explicitly, since Access will do this automatically when you move to another record.

    Try using the Before Update event of the form to check Class:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.Class) Then
    MsgBox "You must enter this student's graduation year!", vbExclamation
    Me.Class.SetFocus
    Cancel = True
    End Sub

    I'm not sure it's a good idea to start a new record - what if the user wants to go back to a previous record? If the user is already on the last record, tabbing out of the last control will take him/her to a new record anyway.

Posting Permissions

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