• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

How do I update existing record


I have an import from csv script... code attached...

I want the code to look if record exist, if it does, all fields must be overwritten by the latest import. A user should be prompted to continue...

Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Set db = session.CurrentDatabase
      Dim uiws As New NotesUIWorkspace
      Dim fileCSV As Variant
      'Declare variables to hold data
      Dim eiref As String
      Dim edu As String
      Dim adu  As String
      Dim rls As String
      Dim tnf As String
      Dim dev As String
      Dim dlv As String
      Dim oah As String
      Dim oar As String
      Dim exd As String
      Dim cur As String
      Dim crc As String
      Dim dv As String
      Dim mn As String
      Dim io As String
      Dim counter As Integer
      Dim doc As NotesDocument
      counter =0
      'setup file number
      filenum% = Freefile()
      'Ask user for file location      
      fileCSV =  uiws.OpenFileDialog(False, "Choose the CSV file","*.txt" ,"c:\temp")
      'If the user chose a file then process
      If Not Isempty(fileCSV ) Then
            Open fileCSV(0) For Input As filenum%
            Do Until Eof(filenum%)
                  'Read a line of data
                  Input #filenum%,  EIREF, EDU, ADU, RLS, TNF,DEV,DLV,OAH,OAR,EXD,CUR,CRC,DV,MN,IO
                  'Create Notes document and write values to it
                  Set doc = db.CreateDocument
                  With doc
                        .ei_ref = eiref
                        .edu = edu
                        .adu = adu
                        .rls = rls
                        .tnf = tnf
                        .dev = dev
                        .dlv = dlv
                        .oah = oah
                        .oar = oar
                        .exd = exd
                        .cur = cur
                        .crc = crc
                        .dv_ref = dv
                        .mn_ref = mn
                        .io_ref = io
                        .Form = "Form"
                  End With
                  'save document
                  Call doc.save(False, False)
                  counter = counter +1
            Msgbox "You imported " & counter & " records."
      End If
End Sub
1 Solution
So you want to search for a doc before you create one ?
After your line :   'Create Notes document and write values to it

change it to :
Set view = db.GetView ("Your sorted view in which docs are visible" )
Set doc = view.GetDocumentByKey (the key you want to search for)
If (doc Is Nothing) Then
dim answer As Integer
Set doc = db.CreateDocument
answer = msgbox "Continue......or Cancel.....?,1,"what to do next"
if answer <> 1 then goto somewhere in the end of your loop
end if
 With doc
   ' your code
car701015Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now