Results 1 to 2 of 2
  1. #1
    brose is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    4

    Save and copy to new record

    Hello,



    I am using the code below to copy values from the current record and populate to new record. It works great unless one of the fields is null. How can I evaluate for and skip over fields with null value?


    Private Sub CopyNew_Click()
    If Me.doValidate = False Then Exit Sub
    DoCmd.RunCommand acCmdSaveRecord
    Dim ID As Long

    ID = Me.ID
    DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
    Provider = DLookup("Provider", "[2018]", "ID=" & ID)
    DATE = DLookup("DATE", "[2018]", "ID=" & ID)
    [Patient Number] = DLookup("[Patient Number]", "[2018]", "ID=" & ID)
    [Pt FirstName] = DLookup("[Pt FirstName]", "[2018]", "ID=" & ID)
    [Pt LastName] = DLookup("[Pt LastName]", "[2018]", "ID=" & ID)
    DOB = DLookup("DOB", "[2018]", "ID=" & ID)
    Cancer = DLookup("Cancer", "[2018]", "ID=" & ID)
    [APPT Type (FU, DR, DC, NP)] = DLookup("[APPT Type (FU, DR, DC, NP)]", "[2018]", "ID=" & ID)
    [MA Verified By] = DLookup("[MA Verified By]", "[2018]", "ID=" & ID)
    [MA Verification Date] = DLookup("[MA Verification Date]", "[2018]", "ID=" & ID)
    [Tracking #] = DLookup("[Tracking #]", "[2018]", "ID=" & ID)
    [Status] = DLookup("Status", "[2018]", "ID=" & ID)





    End Function

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,144
    Wrap each Dlookup() in a Nz() function with a default replacement value for the null e.g.

    Code:
    Provider = Nz(DLookup("Provider", "[2018]", "ID=" & ID),"YourDefaultForProvider")
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Save a Copy of Entire DB
    By somewageslave in forum Access
    Replies: 7
    Last Post: 01-16-2018, 08:39 AM
  2. Replies: 1
    Last Post: 07-02-2013, 08:39 AM
  3. Replies: 3
    Last Post: 03-09-2013, 10:39 AM
  4. Replies: 3
    Last Post: 10-08-2012, 08:40 AM
  5. Replies: 8
    Last Post: 09-27-2012, 11:12 AM

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