?
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
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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