thucgia > 15-10-15, 08:33 PM
maidinhdan > 15-10-15, 08:39 PM
(15-10-15, 08:33 PM)thucgia Đã viết: Mình có đoạn load da ta từ recordset vào form, nó kết nối được nhưng tại sao không cho chỉnh sửa nhỉ? giúp mình với, cám ơn
file access
ongke0711 > 15-10-15, 10:04 PM
thucgia > 15-10-15, 10:47 PM
(15-10-15, 10:04 PM)ongke0711 Đã viết: bác đổi cái rs.LockType = adLockOptimistic
Option Compare Database
Function get_constrN() As String
Dim myPath As String
Dim myPass As String
myPath = CurrentProject.Path & "\" & "van_de_ado_be.accdb"
myPass = ""
get_constrN = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & myPath & ";Jet OLEDB:Database Password=" & myPass & ";"
End Function
Function LayDanhSach() As ADODB.Recordset
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Set conn = New ADODB.Connection
If conn.State = adStateClosed Then
conn.ConnectionString = get_constrN
conn.Open
Else
End If
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
rs.CursorType = adOpenStatic 'adOpenUnspecified 'adOpenStatic 'adOpenKeyset 'adOpenDynamic 'adOpenStatic
rs.LockType = adLockOptimistic
rs.Open "SELECT * FROM nx", conn
Set LayDanhSach = rs
End Function
Option Compare Database
Private Sub btn_add_Click()
'DoCmd.OpenForm "F_nx", , , , , , "new;0"
End Sub
Private Sub btn_del_Click()
'ado_nx.Xoa (Me.id)
Call reload
End Sub
Private Sub btn_edit_Click()
'DoCmd.OpenForm "F_nx", , , , , , "edit;" & Me.id
End Sub
Private Sub Form_Close()
Dim rs As ADODB.Recordset
Set rs = Me.Recordset
Set rs = Nothing
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.reload
End Sub
Sub reload()
Set Me.Recordset = MyAdo.LayDanhSach 'ado_nx.LayDanhSach
End Sub
ongke0711 > 15-10-15, 11:05 PM
thucgia > 15-10-15, 11:46 PM
(15-10-15, 11:05 PM)ongke0711 Đã viết: Đổi luôn CursorLocation=adUseClient.
Function LayDanhSach() As ADODB.Recordset
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Set conn = New ADODB.Connection
If conn.State = adStateClosed Then
conn.ConnectionString = get_constrN
conn.Open
Else
End If
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "SELECT * FROM nx", conn, adOpenStatic, adLockOptimistic
Set LayDanhSach = rs
End Function