Results 1 to 8 of 8
  1. #1
    derek7467 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    46

    MsgBox for Error Handling

    Hey guys-


    I have a small form i use for input from users into a database. I set the database fields to be required, thus kicking off a handling error when trying to save a record with not all fields having data in them.

    I would like to build this into my save button:

    If any of the fields are null Then
    MsgBox ("Please do not leave anything blank") and
    Return to current record using is attempting to submit

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Is this what you're looking for?

    http://www.baldyweb.com/BeforeUpdate.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    derek7467 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    46
    wow! yea it is
    Question, i am a beginner with VBA.. can you walk me thru this code:

    If Len(Me.SomeControl & vbNullString) = 0 Then
    MsgBox "You need to fill out SomeControl"
    Cancel = True
    Me.SomeControl.SetFocus
    End If
    What would i put for Me.SomeControl? I have 1 Combo box, 1 text label as a date, 1 drop down selection list and one text box. I would want each checked not to be null.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    SomeControl would be the name of your control. There's more than one way to test for the empty controls.

    If Len(Me.comboboxname & vbNullString) = 0 Then
    ...
    ElseIf Me.textboxname & "" = "" Then
    ...
    End If

    What do you mean by 'text label as a date'? Label control cannot be altered by user so it should be irrelevant.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    derek7467 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    46
    perfect. Next part, how do i stop the statement from continuing until the null item is no longer null?

    Private Sub Command6_Click()
    If Len(Me.Combo193 & vbNullString) = 0 Then
    MsgBox ("Fill Out Empty Employee name")
    DO NOT PASS THIS PART UNTIL NULL FIELD IS FILLED OUT
    DoCmd.Save
    If MsgBox("Your entry has been submitted. Would you like to submit another?", vbYesNo, "Service Desk Management Enhancement Form") = vbYes Then
    DoCmd.GoToRecord , , acNewRec
    Else
    DoCmd.GoToRecord , , acNewRec
    End If
    End If
    End Sub

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Code:
    Private Sub Command6_Click()
    If Len(Me.Combo193 & vbNullString) = 0 Then
       MsgBox ("Fill Out Empty Employee name")
    Else
       DoCmd.RunCommand acCmdSaveRecord
       If MsgBox("Your entry has been submitted.  Would you like to submit another?", vbYesNo, "Service Desk Management Enhancement Form") = vbYes Then
           DoCmd.GoToRecord , , acNewRec
       End If
    End If
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I guess I'll go off duty.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    derek7467 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    46
    Thank you

Please reply to this thread with any new information or opinions.

Similar Threads

  1. error handling
    By slimjen in forum Forms
    Replies: 6
    Last Post: 03-13-2013, 11:49 AM
  2. Error Handling Question - On Error Goto
    By redbull in forum Programming
    Replies: 7
    Last Post: 12-06-2012, 07:54 AM
  3. Replies: 3
    Last Post: 09-05-2012, 10:23 AM
  4. On Error handling
    By rivereridanus in forum Access
    Replies: 2
    Last Post: 06-18-2012, 07:46 AM
  5. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums