Solved

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

Posted on 2002-04-29
9
177 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

  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 article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

9 Experts available now in Live!

Get 1:1 Help Now