Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2005, 04:56 AM
Authorized User
 
Join Date: Jan 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Edit method

Hello can someone tell me how to implement DAO edit method in ADO? I am stucked here.

 
Old April 27th, 2005, 05:09 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

See a sample from MSDN

Public Sub ModifyRow()
    ' Demonstrate how you modify data.

    Dim rst As ADODB.Recordset

    Set rst = New ADODB.Recordset
    Set rst.ActiveConnection = CurrentProject.Connection
    rst.CursorType = adOpenKeyset
    rst.LockType = adLockOptimistic
    rst.Source = "tblCustomers"
    rst.Open Options:=adCmdTable
    With rst
        .Find "[ContactTitle] = 'Owner'"
        If .EOF Then
            MsgBox "No Match was Found!"
        Else
            .Fields("ContactTitle") = "Manager"
            .Update
        End If
    End With
    rst.Close
    Set rst = Nothing
End Sub




 
Old April 28th, 2005, 02:18 AM
Authorized User
 
Join Date: Jan 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how would you convert the followig DAO code ADO.
Date.Edit
    If Date![Calculate.Project] = A1 Then Date
![Calculate.release] = d(n)
    If Date![Calculate.Project] = A1 Then Date![Calculate.keep] = dh(n)
    Date.Update

 
Old April 28th, 2005, 02:52 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You have lots of examples in MSDN
Another full One Which will solve your problem

Update and CancelUpdate Methods Example (VB)
This example demonstrates the Update method in conjunction with the CancelUpdate method.

'BeginUpdateVB
Public Sub Main()
    On Error GoTo ErrorHandler

    'To integrate this code
    'replace the data source and initial catalog values
    'in the connection string

    ' recordset and connection variables
    Dim rstEmployees As ADODB.Recordset
    Dim Cnxn As ADODB.Connection
    Dim strCnxn As String
    Dim strSQLEmployees As String
     ' buffer variables
    Dim strOldFirst As String
    Dim strOldLast As String
    Dim strMessage As String

    ' Open connection
    Set Cnxn = New ADODB.Connection
    strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _
        "Initial Catalog='Pubs';Integrated Security='SSPI';"
    Cnxn.Open strCnxn

    ' Open recordset to enable changes
    Set rstEmployees = New ADODB.Recordset
    strSQLEmployees = "SELECT fname, lname FROM Employee ORDER BY lname"
    rstEmployees.Open strSQLEmployees, Cnxn, adOpenKeyset, adLockOptimistic, adCmdText

    ' Store original data
    strOldFirst = rstEmployees!fname
    strOldLast = rstEmployees!lname
    ' Change data in edit buffer
    rstEmployees!fname = "Linda"
    rstEmployees!lname = "Kobara"

    ' Show contents of buffer and get user input
    strMessage = "Edit in progress:" & vbCr & _
        " Original data = " & strOldFirst & " " & _
        strOldLast & vbCr & " Data in buffer = " & _
        rstEmployees!fname & " " & rstEmployees!lname & vbCr & vbCr & _
        "Use Update to replace the original data with " & _
        "the buffered data in the Recordset?"

    If MsgBox(strMessage, vbYesNo) = vbYes Then
        rstEmployees.Update
    Else
        rstEmployees.CancelUpdate
    End If

    ' show the resulting data
    MsgBox "Data in recordset = " & rstEmployees!fname & " " & _
       rstEmployees!lname

    ' restore original data because this is a demonstration
    If Not (strOldFirst = rstEmployees!fname And _
           strOldLast = rstEmployees!lname) Then
        rstEmployees!fname = strOldFirst
        rstEmployees!lname = strOldLast
        rstEmployees.Update
    End If

    ' clean up
    rstEmployees.Close
    Cnxn.Close
    Set rstEmployees = Nothing
    Set Cnxn = Nothing
    Exit Sub

ErrorHandler:
    ' clean up
    If Not rstEmployees Is Nothing Then
        If rstEmployees.State = adStateOpen Then rstEmployees.Close
    End If
    Set rstEmployees = Nothing

    If Not Cnxn Is Nothing Then
        If Cnxn.State = adStateOpen Then Cnxn.Close
    End If
    Set Cnxn = Nothing

    If Err <> 0 Then
        MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If
End Sub
' EndUpdateVB







Similar Threads
Thread Thread Starter Forum Replies Last Post
edit gridview anurag_ur ASP.NET 2.0 Basics 3 June 21st, 2006 03:21 AM
edit gridview anurag_ur ASP.NET 2.0 Basics 0 June 20th, 2006 07:57 AM
TAB AND EDIT pallone Javascript How-To 5 January 27th, 2006 08:18 PM
rst.edit method Sympac Access 0 August 30th, 2004 03:50 PM
edit, update method life_s Ng ASP.NET 1.0 and 1.1 Basics 5 August 19th, 2003 10:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.