Sunday, 29 January 2012

Building Forms with ADO Connections

Building forms with ADO connections makes them more flexible and user friendly. The forms are easy to operate and also work well with the database below.
Private Sub Command1_Click()
Dim ado1 As New ADODB.Connection
Dim rs As ADODB.Recordset

ado1.Open "DSN=dsn1"
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Source = "Personal"
rs.ActiveConnection = ado1
rs.Open

rs.AddNew
rs.Fields("Name") = "" & Text1.Text
rs.Fields("Address") = "" & Text2.Text
rs.Fields("Phone Number") = "" & Text3.Text
rs.Fields("Company Name") = "" & Text4.Text
rs.Update

rs.Close
ado1.Close
Set rs = Nothing
Set cn = Nothing

No comments:

Post a Comment