lehongduc > 20-06-12, 06:51 PM
lehongduc > 20-06-12, 11:37 PM
lehongduc > 21-06-12, 01:04 PM
lehongduc > 22-06-12, 08:35 AM
'Ten
Public Property Get Ten() As String
On Error Resume Next
Ten = strTen
End Property
Public Property Let Ten(ByVal Value As String)
On Error Resume Next
strTen = Value
End Property
‘-----------------------------------------------------------------------
'HoChulot
Public Property Get HoChulot() As String
On Error Resume Next
HoChulot = strHochulot
End Property
Public Property Let HoChulot(ByVal Value As String)
On Error Resume Next
strHochulot = Value
End Property
Private Sub Class_Initialize()
‘viết code của Bạn ở vùng này
End Sub
Private Sub Class_Terminate()
‘viết code của Bạn ở vùng này
End Sub
lehongduc > 23-06-12, 08:51 PM
Sub OpenDbConnection()
'
'Co the tham khao chuoi ket noi den cac nguon du lieu khac nhau
'tai dia chi sau: www.connectstring.com
On Error GoTo HandleError
Dim vServer, vData, vUser, vPsw, vLogInDft As Boolean
With Forms("frmLogIn")
vLogInDft = !chkLogIn.Value
If vLogInDft = True Then
vServer = "mssql.quantribanhang.vn"
vData = "danhba"
vUser = "nhanvien1"
vPsw = "Nv001"
Else
vServer = !txtServer
vData = !txtData
vUser = !txtUser
vPsw = !txtPsw
End If
End With
Set cnConn = New ADODB.Connection
cnConn.Open _
"Provider = sqloledb;" & _
"Data Source=" & vServer & ";" & _
"Initial Catalog=" & vData & ";" & _
"User ID=" & vUser & ";" & _
"Password=" & vPsw & ";"
Exit Sub
HandleError:
GeneralErrorHandler Err.Number, Err.Description, DB_QUANLY, "OpenDbConnection"
Exit Sub
End Sub
cnConn.Open _
"Provider = sqloledb;" & _
"Data Source=" & vServer & ";" & _
"Initial Catalog=" & vData & ";" & _
"User ID=" & vUser & ";" & _
"Password=" & vPsw & ";"
Function FixNull(varIn As Variant) As String
If IsNull(varIn) Then
FixNull = ""
Else
FixNull = varIn
End If
End Function
Sub PopulatePropertiesFromForm()
'Lay thong tin tu Form frmContacts de gan gia tri cac thuoc tinh cho objDanhba
On Error GoTo HandleError
With Me
.Ten = FixNull(Forms("frmContacts")!txtTen)
.HoChulot = FixNull(Forms("frmContacts")!txtHoChulot)
.Diachi = FixNull(Forms("frmContacts")!txtDiachi)
.Dtdd = FixNull(Forms("frmContacts")!txtDtdd)
.Dtnha = FixNull(Forms("frmContacts")!txtDtnha)
.Dtvp = FixNull(Forms("frmContacts")!txtDtvp)
If Len(Forms("frmContacts")!txtNgaysinh) > 0 Then
.Ngaysinh = Forms("frmContacts")!txtNgaysinh
Else
.Ngaysinh = Null
End If
.Gioitinh = Forms("frmContacts")!frmGioitinh.Value
End With
Exit Sub
HandleError:
GeneralErrorHandler Err.Number, Err.Description, CLS_DANHBA, "PopulatePropertiesFromForm"
Exit Sub
End Sub
Sub PopulatePropertiesFromRecordset(rsCont As ADODB.Recordset)
'Lay thong tin tu Recordset rsCont de gan gia tri cac thuoc tinh cho objDanhba
On Error GoTo HandleError
With Me
.DanhbaId = rsCont!DanhbaId
.Ten = Trim(FixNull(rsCont!Ten))
.HoChulot = Trim(FixNull(rsCont!HoChulot))
.Diachi = Trim(FixNull(rsCont!Diachi))
.Dtdd = Trim(FixNull(rsCont!Dtdd))
.Dtnha = Trim(FixNull(rsCont!Dtnha))
.Dtvp = Trim(FixNull(rsCont!Dtvp))
If Not IsNull(rsCont!Ngaysinh) Then
.Ngaysinh = rsCont!Ngaysinh
Else
.Ngaysinh = ""
End If
.Gioitinh = rsCont!Gioitinh
End With
Exit Sub
HandleError:
GeneralErrorHandler Err.Number, Err.Description, CLS_DANHBA, "PopulatePropertiesFromRecordset"
Exit Sub
End Sub
Public Sub GeneralErrorHandler(lngErrNumber As Long, strErrDesc As String, strModuleSource As String, strProcedureSource As String)
On Error Resume Next
Dim strMessage As String
'build the error message string from the parameters passed in
strMessage = "An error has occurred in the application."
strMessage = strMessage & vbCrLf & "Error Number: " & lngErrNumber
strMessage = strMessage & vbCrLf & "Error Description: " & strErrDesc
strMessage = strMessage & vbCrLf & "Module Source: " & strModuleSource
strMessage = strMessage & vbCrLf & "Procedure Source: " & strProcedureSource
'display the message to the user
MsgBox strMessage, vbCritical
Exit Sub
End Sub
...
On Error GoTo HandleError
...
HandleError:
GeneralErrorHandler Err.Number, Err.Description, <Tên module>, <Tên procedure>
Exit Sub
lehongduc > 24-06-12, 07:16 AM
...
strSQLInsert = "INSERT INTO " & sChemaName & ".tblDanhsach(ten,hochulot, diachi,dtdd, dtnha, dtvp,ngaysinh, gioitinh)"
strSQLInsert = strSQLInsert & " VALUES ("
strSQLInsert = strSQLInsert & "N'" & objDanhba.Ten & "', "
strSQLInsert = strSQLInsert & "N'" & objDanhba.HoChulot & "', "
strSQLInsert = strSQLInsert & "N'" & objDanhba.Diachi & "', "
strSQLInsert = strSQLInsert & "'" & objDanhba.Dtdd & "', "
strSQLInsert = strSQLInsert & "'" & objDanhba.Dtnha & "', "
strSQLInsert = strSQLInsert & "'" & objDanhba.Dtvp & "', "
...
lehongduc > 26-06-12, 08:32 AM
Dim objDanhba As clsDanhba
Set objDanhba = New clsDanhba
...
...
rsDanhba.Close
Set rsDanhba = Nothing
...
Option Compare Database
Option Explicit
Dim blnAddMode As Boolean
Dim rsDanhba As ADODB.Recordset
Dim objDanhba As clsDanhba
Const Danhba_FORM = "frmDanhba"
Dim intCurrDanhbaRecord As Integer
Dim rsSearch As ADODB.Recordset
Dim RecSearch As Boolean
lehongduc > 26-06-12, 11:12 AM
Sub PopulatePropertiesFromRecordset(rsCont As ADODB.Recordset)
'Lay thong tin tu Recordset rsCont de gan gia tri cac thuoc tinh cho objDanhba
On Error GoTo HandleError
With Me
.DanhbaId = rsCont!DanhbaId
.Ten = Trim(FixNull(rsCont!Ten))
.HoChulot = Trim(FixNull(rsCont!HoChulot))
.Diachi = Trim(FixNull(rsCont!Diachi))
.Dtdd = Trim(FixNull(rsCont!Dtdd))
.Dtnha = Trim(FixNull(rsCont!Dtnha))
.Dtvp = Trim(FixNull(rsCont!Dtvp))
If Not IsNull(rsCont!Ngaysinh) Then
.Ngaysinh = rsCont!Ngaysinh
Else
.Ngaysinh = ""
End If
.Gioitinh = rsCont!Gioitinh
End With
Exit Sub
HandleError:
GeneralErrorHandler Err.Number, Err.Description, CLS_DANHBA, "PopulatePropertiesFromRecordset"
Exit Sub
End Sub
lehongduc > 28-06-12, 09:07 AM
Public Property Let DanhbaId(ByVal Value As Long)
On Error Resume Next
lngDanhbaid = Value
End Property
Public Property Get DanhbaId() As Long
On Error Resume Next
DanhbaId = lngDanhbaid
End Property
lehongduc > 29-06-12, 11:48 AM