Results 1 to 4 of 4
  1. #1
    specialvat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2016
    Posts
    8

    How to clear a form using aDate macro

    Hi,


    Sorry if this is an easy fix I'm a newbie.
    I have a database
    ID Date Serial Number
    1 17/02/16 90001234
    2 17/02/16 90001243
    3 17/02/16 90001212
    4 17/02/16 90009999
    5 17/02/16 90009999

    I am using a form to enter the data.
    I have a macro which checks if the serial number has been previously used.
    This is before update.

    The macro is:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If DCount("ID", "YourTableName", "[Serial Number] = '" & Me.[Serial Number] & "'") > 0 Then
    Response = MsgBox ("Serial Number previously used.Click Yes to continue or No to clear.", VbQuestion + VbYesNo
    If Response = vbNo then ****Clear form code ****
    End If
    End If
    End Sub

    The code check if the serial number has been previously used.
    If it has it asked you the Question to continue or clear.
    If you continue it updates the database.
    I need it to clear the form when No is clicked.
    Any ideas greatly appreciated





  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    try

    Code:
    If Response = vbNo then ****Clear form code ****
        me.Undo
    End If
    Also for future reference please learn to use the code tags - this example is pretty short but longer bits of code become unreadable without indentation - you know it because you wrote it - but we don't.

  3. #3
    specialvat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2016
    Posts
    8
    Hi just add the code to the macro.
    I seemed to work but the serial was deleted but the two other
    field stay.
    Now when you enter another one the database is not updated.
    Do you mean smart codes?

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    OK, try replacing

    me.undo

    with

    me.dirty=false

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access 2013 Macro to clear CSV file
    By m698322h in forum Access
    Replies: 3
    Last Post: 02-15-2016, 02:08 PM
  2. How can i clear a query with vba or macro?
    By omeara4pheonix in forum Macros
    Replies: 7
    Last Post: 06-18-2013, 09:05 PM
  3. Macro to add and clear fields
    By Skroof in forum Access
    Replies: 1
    Last Post: 05-14-2012, 01:13 PM
  4. Clear Form
    By hithere in forum Access
    Replies: 4
    Last Post: 03-28-2012, 09:28 AM
  5. How to clear the form?
    By Mrcams in forum Access
    Replies: 3
    Last Post: 01-03-2011, 12:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums