Results 1 to 4 of 4
  1. #1
    akika is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    27

    Ms Access 2016: validation and create duplicate record when not null


    hi,


    In access2016,
    How can i create a duplicated record in the main DB table if my field for 'date_closed' is not null.
    Contact_ID Contact_LastName Status Contact_Tel date_closed
    1 Smith Rejected contact tel test 1 01/09/2018
    2 Paul Complete contact tel test 2
    3




    And also i have below validation that should be raised only when field 'status' is set rejected and date_closed is not null.


    Code:
    Private Sub contact _name_BeforeUpdate(Cancel As Integer)
    
    
    If IsNull(DLookup("[contact Name]", _
    "Database", _
    "[contact Name] = """ & Me.contact_name.Text & """")) = False Then
    Cancel = True
    MsgBox "contact Name already exists", vbOKOnly, "Warning"
    Me![contact Name].Undo
    End If
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    Don't use .Text property. Should be .Value but since .Value is default, no need to type it.

    Why create 'duplicate' record? When do you want this duplication to take place?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    akika is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    27
    Quote Originally Posted by June7 View Post
    Don't use .Text property. Should be .Value but since .Value is default, no need to type it.

    Why create 'duplicate' record? When do you want this duplication to take place?
    Hi,
    - To maintain a kind of history record (original record and amended record)..
    - Duplication of record should occur when field 'status' is set rejected and date_closed is not null. then all the data for that record should be replicated.

    Any suggestion pls?



    Contact_ID Contact_LastName Status Contact_Tel date_closed
    1 Smith Rejected contact tel test 1 01/09/2018
    2 Paul Complete contact tel test 2
    3

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    If you want an audit trail functionality, review http://allenbrowne.com/AppAudit.html

    Otherwise, to create record in data table, need code in some event, perhaps date_closed AfterUpdate.

    And if validation needs to be raised only under the described condition then use an If Then structure.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 8
    Last Post: 01-26-2018, 05:01 PM
  2. Replies: 7
    Last Post: 01-04-2018, 06:35 PM
  3. Replies: 2
    Last Post: 02-23-2016, 04:36 PM
  4. Replies: 1
    Last Post: 11-21-2013, 12:17 PM
  5. Replies: 20
    Last Post: 09-12-2012, 06:52 PM

Tags for this Thread

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