Solved

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

Posted on 2002-04-29
9
178 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Accepted Solution

by:
jaynee earned 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now