-
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?
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks