i have written a employee class .there are some properties i want to access database fields data through this property can anbody help me any help would be greately appreciated. Kindly find the
attachment also.
Private m_sname As String
'local variable(s) to hold property value(s)
Private m_iemployeeid As Long
Private m_sposition As String
Private m_sdepartment As String
Public Property Get EmployeeName() As String
EmployeeName = m_sname
End Property
Public Property Let EmployeeName(ByVal vNewValue As String)
m_sname = vNewValue
End Property
Public Property Get Position() As String
Position = m_sname
End Property
Public Property Let Position(ByVal vNewValue As String)
m_sposition = vNewValue
End Property
Public Property Get ID() As Long
ID = m_iemployeeid
End Property
Public Property Let ID(ByVal vNewValue As Long)
m_iemployeeid = vNewValue
End Property
Public Property Get Department() As Variant
Department = m_sdepartment
End Property
Public Property Let Department(ByVal vNewValue As Variant)
m_sdepartment = vNewValue
End Property
here is the code for form1.how should i put database fields using property value. i am still confuse.Kindly help me .any help would be greately appreciated.
Code:
Option Explicit
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim emp As Employee
Private Sub Form_Load()
SaveSetting App.Title, "Projecttitle", "abc", ""
'Debug.Print filename
Set con = New ADODB.Connection
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=c:\Product_table.mdb")
End Sub
Private Sub Text1_LostFocus()
If Text1.Text <> " " Then
Set rs = New ADODB.Recordset
rs.Open "select * from employees where employee_id=" & Val(Text1.Text), con, adOpenDynamic, adLockOptimistic
If rs.EOF Then
MsgBox ("Employee id not found")
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text4.Text = " "
Text1.SetFocus
Else
Set emp = New Employee
emp.ID = IIf(IsNull(rs!employee_id), "", rs!employee_id)
Text2.Text = IIf(IsNull(emp.EmployeeName), "", emp.EmployeeName)
Text3.Text = IIf(IsNull(emp.Position), "", emp.Position)
emp.Department = IIf(IsNull(rs!Department_id), "", rs!Department_id)
Text4.SetFocus
End If
End If
Exit Sub
End Sub