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 / Modules / DAO / VBA / July 2007

Tip: Looking for answers? Try searching our database.

Clear data entered

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Penstar - 07 Jul 2007 03:06 GMT
I have the following code in a from where user is to enter New Ingredient.  
It catches the error when a duplicate Ingredient ID is used.  It works so
far, but what I want it to do is to clear the incorrect IngredientID they
have started to enter it.  I can't figure out what code to put after the
message box

Private Sub IngredientID_BeforeUpdate(Cancel As Integer)
   Dim varIngredientID As Variant
   Dim strType As String, strWhere As String
   
   strType = Me.IngredientID
   strWhere = "[IngredientID]=""" & strType & """"
   
   If IsNull(DLookup("IngredientID", "dbo_Ingredients", strWhere)) Then
         
   Else
   MsgBox "The Ingredient Code you have entered already exists.  Please use
a Unique Code"
   
   End If
   
End Sub
Marshall Barton - 07 Jul 2007 04:08 GMT
>I have the following code in a from where user is to enter New Ingredient.  
>It catches the error when a duplicate Ingredient ID is used.  It works so
[quoted text clipped - 18 lines]
>    
>End Sub

Add two lines after the MsgBox:

    Cancel = True
    Me.IngredientID.Undo

Signature

Marsh
MVP [MS Access]

Penstar - 07 Jul 2007 05:20 GMT
Thank you so much.  I thought there would be an easy solution.

Though, to clear the record I used
    Cancel=True
    Me.Undo
(when I just used Me.IngredientID.Undo I got a further error message)

Penny

> >I have the following code in a from where user is to enter New Ingredient.  
> >It catches the error when a duplicate Ingredient ID is used.  It works so
[quoted text clipped - 23 lines]
>     Cancel = True
>     Me.IngredientID.Undo
Marshall Barton - 07 Jul 2007 15:51 GMT
Glad to able to help.

If the ingredient is essentially the record, then, yes, you
want to undo the whole record.
Signature

Marsh
MVP [MS Access]

>Thank you so much.  I thought there would be an easy solution.
>
[quoted text clipped - 30 lines]
>>     Cancel = True
>>     Me.IngredientID.Undo
 
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.