ADO Controls help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: ADO Controls help

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    ADO Controls help

    [Originally posted by V. Sastry]

    I am using a ado contol to connect to a MS Access database.˙ How do i reset and go˙ back to the previous/last record in the data base after creating a new record using the addnew method, without saving changes in the current record?

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:ADO Controls help

    [Originally posted by remus bodean]

    A simple exemple:
    You need 1 form with 2 command buttons named command1 with "add new" caption, command2 with "Cancel" caption and disabled, an ado control named adcodc1 ( bound to eg Northwind , cmdTable - table Employers , of course in design mode) and 3 text boxes, text1, text2, text3 with data source set to adodc1 and datafields set to lastname, firstname and birthdate ( in design mode ). Here it is the code:

    dim bmk

    Select Case Command1.Caption
    Case "add new"
    ˙ ˙ Command1.Caption = "save"
    ˙ ˙ bmk = Adodc1.Recordset.Bookmark
    ˙ ˙ 'unbind the text boxes
    ˙ ˙ Set Text1.DataSource = Nothing
    ˙ ˙ Set Text2.DataSource = Nothing
    ˙ ˙ Set Text3.DataSource = Nothing
    ˙ ˙ Text1 = "": Text2 = "": Text3 = "": Command2.Enabled = True

    Case "save"
    ˙ ˙ If Not IsDate(Text3) Then Exit Sub
    ˙ ˙ With Adodc1.Recordset
    ˙ ˙ ˙ ˙ .AddNew
    ˙ ˙ ˙ ˙ .Fields("LastName").Value = Text1
    ˙ ˙ ˙ ˙ .Fields("FirstName").Value = Text2
    ˙ ˙ ˙ ˙ .Fields("BirthDate").Value = Text3
    ˙ ˙ ˙ ˙ .Update
    ˙ ˙ End With
    ˙ ˙ Command1.Caption = "add new"
    ˙ ˙ Command2.Enabled = False
    ˙ ˙ 'rebind the text boxes
    ˙ ˙ Set Text1.DataSource = Adodc1
    ˙ ˙ Set Text2.DataSource = Adodc1
    ˙ ˙ Set Text3.DataSource = Adodc1
    End Select
    End Sub

    Private Sub Command2_Click()
    ˙ ˙ Set Text1.DataSource = Adodc1
    ˙ ˙ Set Text2.DataSource = Adodc1
    ˙ ˙ Set Text3.DataSource = Adodc1
    ˙ ˙ Adodc1.Recordset.Bookmark = bmk
    ˙ ˙ Command1.Caption = "add new"
    ˙ ˙ Command2.Enabled = False
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center