Results 1 to 2 of 2

Thread: Error Handling

  1. #1
    Join Date
    Jan 2013
    Posts
    18

    Unanswered: Error Handling

    I Will be promting a User With a Message Box asking them to enter a LanID and if they enter a LanID that doesnt exist i want a error box to pop up telling them it doesnt exist. Then it will ask for it again. How Do i Do This?

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    In the BeforeUpdate event of the Control where the LanID is being entered you can use DCount against the Table or Query that holds the LanIDs to see if it returns more than zero.

    If LanID is defined as a Number
    Code:
    Private Sub txtLanID_BeforeUpdate(Cancel As Integer)
     
     If Not DCount("*", "YourTableName", "LanID = " & Me.txtLanID) > 0 Then
       MsgBox "This LanID Does Not Exist; Please Re-enter LanID!"
       Cancel = True
     End If
     
    End Sub

    If LanID is defined as Text
    Code:
    Private Sub txtLanID_BeforeUpdate(Cancel As Integer)
     
     If Not DCount("*", "YourTableName", "LanID = '" & Me.txtLanID & "'") > 0 Then
       MsgBox "This LanID Does Not Exist; Please Re-enter LanID!"
       Cancel = True
     End If
     
    End Sub

    Replacing YourTableName with the actual name of the Table that holds the LanIDs, LanID with the actual name of the Field in that Form, and txtLanID with the actual name of the Control on your Form where the user enters the LanID.

    The cursor will remain in txtLanID until a valid ID number is entered.

    A way to avoid all of this, though, would be to use a Combobox whose RowSource retrieves all of the LanIDs form that Table, and use this Combobox to populate the txtLanID Control. This way, an invalid ID would never be entered to begin with!

    Linq ;0)>
    Last edited by Missinglinq; 02-21-13 at 23:12.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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