B
Bula
I created a form bound to ADO recordset containing data from DB2
database, but the form is readonly. How can I make the form editable?
Steps:
--Create a form with 4 labels, and 4 text boxes: label 1, label2,
label3, label4, text1, text2, text3, text4.
--Put the following code to the form's open event:
Private Sub Form_Open(Cancel As Integer)
'create an ado connection instance and set its properties
Dim myconnection As ADODB.Connection
Set myconnection = New ADODB.Connection
Dim str As String
str = "Data Provider=IBMDADB2;DSN=sample;User
ID=MyuserID;Password=mypw;"
With myconnection
.Provider = "MSDataShape"
.CursorLocation = adUseClient
.ConnectionString = str
.Open
End With
'create an ado recordset and set its properties
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = myconnection
.Source = "SELECT * FROM admin.staff"
.LockType = adLockOptimistic
.CursorType = adOpenSatic
.Open
End With
'set the form's data source to the ado recordset
Set Me.Recordset = rs
Me.UniqueTable = "staff1"
'bind form controls to recordset fields
Dim x As Integer
For x = 1 To 4
Me.Controls("Label" & x).Caption = rs.Fields(x - 1).Name
Me.Controls("Text" & x).ControlSource = rs.Fields(x - 1).Name
Next
End Sub
database, but the form is readonly. How can I make the form editable?
Steps:
--Create a form with 4 labels, and 4 text boxes: label 1, label2,
label3, label4, text1, text2, text3, text4.
--Put the following code to the form's open event:
Private Sub Form_Open(Cancel As Integer)
'create an ado connection instance and set its properties
Dim myconnection As ADODB.Connection
Set myconnection = New ADODB.Connection
Dim str As String
str = "Data Provider=IBMDADB2;DSN=sample;User
ID=MyuserID;Password=mypw;"
With myconnection
.Provider = "MSDataShape"
.CursorLocation = adUseClient
.ConnectionString = str
.Open
End With
'create an ado recordset and set its properties
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = myconnection
.Source = "SELECT * FROM admin.staff"
.LockType = adLockOptimistic
.CursorType = adOpenSatic
.Open
End With
'set the form's data source to the ado recordset
Set Me.Recordset = rs
Me.UniqueTable = "staff1"
'bind form controls to recordset fields
Dim x As Integer
For x = 1 To 4
Me.Controls("Label" & x).Caption = rs.Fields(x - 1).Name
Me.Controls("Text" & x).ControlSource = rs.Fields(x - 1).Name
Next
End Sub