Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011
    Posts
    413

    Question Unanswered: Can't update field on form

    I gave a field on my form named GirlID which is set to Text in the table. When I try to enter data into it I get the error message; Can't update field. Then after 2 tries it let's me enter the data. Here is the only code tun on this field. There is a max number of 20 set in the table of field length but the data in the field never approaches that.

    Private Sub GirlID_AfterUpdate()
    If DCount("GirlID", "tbl_main", "[GirlID] = '" & Me.GirlID & "'") > 0 Then

    MsgBox "This Girl Already Exists! Try Again?"
    'GirlID = StrConv(GirlID, vbProperCase)
    End If
    End Sub

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    This type of Validation code belongs in the Control's BeforeUpdate event, not in the AfterUpdate event!

    You ask the question "Try Again?" but you make no allowance if they answer 'No;" actually, your Messagebox, as written, here, won't even offer a Yes/No Button.

    But see if this does what you need:

    Code:
    Private Sub GirlID_BeforeUpdate(Cancel As Integer)
     If DCount("GirlID", "tbl_main", "[GirlID] = '" & Me.GirlID & "'") > 0 Then
      MsgBox "This Girl Already Exists! Try Again?"
      Cancel = True
     End If
    
     Me.GirlID = StrConv(Me.GirlID, vbProperCase)
    
    End Sub

    If a duplicate GirlID is found, it will pop your Messagebox and leave the cursor in the GirlID Texbox.

    Linq ;0)>
    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
  •