mrsiro > 27-04-18, 10:56 AM
MTNQ > 28-04-18, 04:25 PM
Option Compare Database
Option Explicit
Private Sub cmdSave_Click()
If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
Me.lstTest.Requery
End Sub
Private Sub Command14_Click()
If FindRec(Me, "[ID] = " & Nz(Me.Text12.Value, 0)) = 0 Then
MsgBox "khong tim thay ID: " & Nz(Me.Text12.Value, 0)
End If
End Sub
Private Sub Form_Current()
If Nz(Me.txtID.Value, 0) <> 0 Then Call FindRec(Me.lstTest, "[ID] = " & Me.txtID.Value)
End Sub
Private Sub lstTest_DblClick(Cancel As Integer)
If Me.lstTest.ItemsSelected.Count > 0 Then
Call FindRec(Me, "[ID] = " & Me.lstTest.Value)
End If
End Sub
Public Function FindRec(objLst As Object, strCriteria As String) As Integer
Dim rst As DAO.Recordset
On Error GoTo ErrorHandler
Set rst = objLst.Recordset.Clone
rst.FindFirst strCriteria
If Not rst.NoMatch Then
If InStr(TypeName(objLst), "ListBox") > 0 Then
objLst.Selected(rst.AbsolutePosition) = True
ElseIf InStr(TypeName(objLst), "Form") > 0 Then
objLst.Bookmark = rst.Bookmark
End If
FindRec = -1
Else
FindRec = 0
End If
Exit_ErrorHandler:
Set rst = Nothing
Exit Function
ErrorHandler:
FindRec = 1
MsgBox "Err: " & Err.Number & vbCrLf & "Description: " & Err.Description
Resume Exit_ErrorHandler
End Function
mrsiro > 28-04-18, 04:34 PM
ongke0711 > 29-04-18, 12:28 AM
mrsiro > 29-04-18, 01:02 AM
MTNQ > 29-04-18, 11:57 AM
mrsiro > 29-04-18, 10:26 PM
(29-04-18, 12:17 PM)MTNQ Đã viết:(29-04-18, 01:02 AM)mrsiro Đã viết: mở bằng access 2003 bị lỗi bạn ơi.
Đã sửa lại cho AC2003, bác tải lại nhé
MTNQ > 30-04-18, 12:52 AM
Private Sub cmdSave_Click()
If Nz(Me.txtID.Value, 0) = 0 Then Exit Sub
DoCmd.RunCommand acCmdSaveRecord
If CurrentProject.AllForms("frmDanhSach").IsLoaded = False Then Exit Sub
Forms.frmDanhSach.Requery
Forms.frmDanhSach.lstTest.Requery
Call FindRec(Forms.frmDanhSach, "[ID] = " & Nz(Me.txtID.Value, 0))
Call FindRec(Forms.frmDanhSach.lstTest, "[ID] = " & Nz(Me.txtID.Value, 0))
DoCmd.Close acForm, Me.Name
End Sub
mrsiro > 30-04-18, 11:28 AM