• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 663
  • Last Modified:

VB6 addNew

Is .addNew and .Update built in methods with vb6?
How do the work?


    Set rsSet = New ADODB.Recordset
   
    strSQL = "SELECT MAX(ID) " & _
             "FROM Table"
             
    With rsSet
        Call .open(strSQL, datDB, adOpenForwardOnly, adLockReadOnly)
       
        If Not .EOF Then
            If Not IsNull(.Fields(0).value) Then
                lngID = .Fields(0).value + 1
            End If
        End If
       
        .Close
       
        strSQL = "SELECT * " & _
                 "FROM Table" & _
                 "WHERE ID = " & lngID
                 
        Call .open(strSQL, datDB, adOpenDynamic, adLockPessimistic)
       
        If .EOF Then
            .addNew
            !LabelSelnValueSetID = lngID
            .Update
        End If
       
        .Close
    End With
0
JRockFL
Asked:
JRockFL
  • 2
2 Solutions
 
käµfm³d 👽Commented:
The "." in front of those two methods indicate that they are a part of the object you referenced in your "With" statement. It is a form of shorthand. If you did not have the "With", the statements would look like:
If rsSet.EOF Then
    rsSet.addNew
    rsSet!LabelSelnValueSetID = lngID
    rsSet.Update
End If

Open in new window

0
 
JRockFLAuthor Commented:
Thanks for your reply.
I'm familiar with the short hand, just not with the addNew method or the Update method.
How does that work? I know what add and update is, but specifically, how do these two methods work?
0
 
Neil RussellTechnical Development LeadCommented:
They either ADD or UPDATE a record in the recordset.

If NOT rsSet.EOF Then
    rsSet!LabelSelnValueSetID = lngID
    rsSet.Update
else
    rsSet.addNew
    rsSet!LabelSelnValueSetID = lngID
    rsSet.Update
End If

Open in new window

0
 
JRockFLAuthor Commented:
So in that code sample I provided
both .addNew and .Update is not needed? Just one of them?
        If .EOF Then
            .addNew
            !LabelSelnValueSetID = lngID
            .Update
        End If
0

Featured Post

Independent Software Vendors: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now