Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / April 2005

Tip: Looking for answers? Try searching our database.

problem with before update event for data validity

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonathan Snyder - 29 Apr 2005 18:34 GMT
Hi all,

I'm using a before update event to validate data entered on a form.  If
data is valid my code works fine.  If data is invalid I want the event
canceled and what ever was entered erased. My code works fine up through
the msgbox, but then the data is not erased and a default message appears
saying a validation rule has been violated. I have no validation rules
attached to the table or form other than this code. I dont understand why
the cancel=true and me.undo statements are not working.

Please help!!

Private Sub Trip_ID_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Trip_ID_BeforeUpdate

Dim trip As String
Dim vill As String
Dim strvill As String
Dim strtrip As String
   vill = Me.Village
   strvill = Left(vill, 1)
   
   trip = Me.Trip_ID
   strtrip = Left(trip, 1)
   
   If strtrip <> strvill Then
       MsgBox "Your Trip ID must begin with the first letter of the
village name", vbOKOnly, "Hey Dude"
       Cancel = True
      Me.Trip_ID.Undo
End If
Rick Brandt - 29 Apr 2005 18:47 GMT
> Hi all,
>
[quoted text clipped - 28 lines]
>        Me.Trip_ID.Undo
> End If

I just ran into this yesterday.  You don't want both Cancel = True and Undo.
Just use the Undo by itself.

Signature

I don't check the Email account attached
to this message.     Send instead to...
RBrandt    at       Hunter      dot      com

Jonathan Snyder - 29 Apr 2005 19:03 GMT
Rick,

thanks, for the suggestion, but using just the undo. supresses the default
validation message, but does not erase the invalid data and does not allow
the focus to be held on that field.  

Any other ideas?
Rick Brandt - 29 Apr 2005 19:21 GMT
> Rick,
>
[quoted text clipped - 3 lines]
>
> Any other ideas?

You're correct.  After reviewing my code I see that I am using Undo of the
entire Form, not of the control.  As I recall that was the only way I could
get rid of the same problem you are having.  Apparently setting Cancel =
True in the BeforeUpdate of a required field is what triggers the validation
message whereas if the entire form is "undone" this doesn't happen.

Signature

I don't check the Email account attached
to this message.     Send instead to...
RBrandt    at       Hunter      dot      com

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.