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, False)
                  counter = counter +1
            Msgbox "You imported " & counter & " records."
      End If
End Sub
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
car701015Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.