Solved

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

Posted on 2002-04-29
9
179 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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