?
Solved

Need to modify my VB code so that I can edit records instead of adding them.

Posted on 2002-04-29
9
Medium Priority
?
186 Views
Last Modified: 2013-12-18
Hello,

I have the following code in VB, which allows me to go through a collection of NotesDocuments and add rows
to a table in  access.
What I want to do is modify the AddNew so that I can edit the row if it already exists in Access. I
tried using seek but couldnt achieve it. Pls help.

For x = 1 To intNotesDocCount
     Set doc = dc.GETNTHDOCUMENT(x)
        .AddNew
         On Error Resume Next
         For Each fld In .Fields
            varGetItem = doc.GETITEMVALUE(fld.Name)(0)
            fld.Value = CStr(varGetItem)                
         Next
         
         .Update
                       
   Next x
 End With
0
Comment
Question by:puneetfred
  • 4
  • 3
  • 2
9 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 6977823
You have to query the table before you insert the field values. That is the only way you can check the existence and update.

~Hemanth
0
 
LVL 7

Expert Comment

by:jaynee
ID: 6980985
I agree with Hermanth - rather than of doing a .AddNew on the Access table/recordset, you need to do a .FindFirst instead, where you have a known unique value for one of the Notes doc fields.  Do you have the doc field names and corresponding access table field names of any fields that can be guaranteed unique?  That makes the .FindFirst statement easier.  After the .FindFirst, you can check .NoMatch and if true, do the .AddNew
0
 

Author Comment

by:puneetfred
ID: 6981202
hi,

i did do seek & yes my fields names match in Notes Doc & Access Table.

what I DONT know is how to edit/ update an already existing record. I even tried deleting & then adding but i wasnt able to. so, if u can tell me the syntax it will be helpful

Thanks!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:puneetfred
ID: 6981234
Just to explain what I need is:

The code on:

how to seek, edit/ update an already existing record.

(I even tried deleting & then adding but i wasnt able to) so, if u can tell me the syntax it will be helpful

My Code again is:

Set rst = CurrentDb.OpenRecordset(stTable, dbOpenDynaset)
 
With rst
For x = 1 To intNotesDocCount
     Set doc = dc.GETNTHDOCUMENT(x)
        .AddNew
         On Error Resume Next
         For Each fld In .Fields
            varGetItem = doc.GETITEMVALUE(fld.Name)(0)
            fld.Value = CStr(varGetItem)                
         Next
         
         .Update
                       
   Next x
 End With

Thanks!
0
 
LVL 7

Accepted Solution

by:
jaynee earned 400 total points
ID: 6983038
Well, you need to know the Access field name (I've called it AccessFieldName) for a unique field value in the Notes doc  (LotusDocFieldValue).  In simple terms, you would be doing this instead:
 
With rst
For x = 1 To intNotesDocCount
    Set doc = dc.GETNTHDOCUMENT(x)
        .FindFirst "[AccessFieldName]=" & LotusDocFieldValue
        If .NoMatch Then
          .AddNew
        Else
          .Edit
        Endif
        For Each fld In .Fields
           varGetItem = doc.GETITEMVALUE(fld.Name)(0)
           fld.Value = CStr(varGetItem)                
        Next
        .Update
  Next x
End With

Why are you using the "On Error Resume Next" statement?  Don't you want to know if soemthing goes wrong?

0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 6983318
Sorry missed this one in my list. Jaynee has it right.
0
 

Author Comment

by:puneetfred
ID: 6983800
Hi Jaynee, thanks for the input but now that i see your answer, i think my question is different.So, I will give you marks for this, and ask u another question after I try it out myself.

Its about Primary Key. If primary key is an autonumber, it is giving errors-duplicate values.let me try it out myself and see if i can do it, i should be able to.

Thanks again!
0
 

Author Comment

by:puneetfred
ID: 6983808
Thanks a Ton!
0
 
LVL 7

Expert Comment

by:jaynee
ID: 6985246
You're welcome, puneetfred.  Let me know if you need more help with the autonumber field.  As long as you are letting Access generate it, and not trying to write to it yourself, you shouldn't have a problem with duplicate values.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question