Thread: Can't update field on form
10-01-12, 00:02 #1Registered User
- Join Date
- Nov 2011
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)
10-01-12, 12:23 #2Moderator
Provided Answers: 19
- Join Date
- Jun 2005
- Richmond, Virginia USA
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:
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