Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Thursday, July 21, 2011

VB - 53 : Create an Employee Profile

==================================================================================

Before going to do any Database Program ,Click here to  understand Database Concepts thoroughly.


That is , Creating Database within VB Platform


==================================================================================

Create a table called "Employee" using the Visual Data Manager with the following fields : Name,Address,Pin code,E-mail,Phone. Write a program using Data Control to display,

  • An Employee's Address and Name if the Phone number is given
  • An Employee's Address and Phone if the Name is given
A)    Program Design : 

This application is based upon Database.
Create a Table named Employee with the following fields. Refer Linking to Database to create a table in Access.



Field Name
Data Type
Name
Text
Address
Text
Pin
Number
E-mail
Text
Phone
Number



(B) Property(Controls Used) :
  • 6 Labels
  • 5 Text Boxes (Name-Text1, Index from 0-5, Visible-False).
  • One Data Control (Name-Data1,Database name-db1,Record Source-Emp2)
  • 4 Command Buttons with Captions Transaction (Name-Command1,Visible-False) ,,Search (Name-Command2,Visible-False),,Find Data (Name-Command3,Visible-False),,MainMenu (Name-cmd_back,Visible-True).
  • Form Name is frmemp_data
When we set some properties of the controls as True or False, the form will appear while running....as,



(C) Attaching Code to the Object :


Private Sub setVisible(flag As Boolean)
Data1.Visible = flag
For Each i In frmemp_data.Controls
If i.Name = "Label1" Then
i.Visible = flag
ElseIf TypeOf i Is TextBox Then
i.Visible = flag
End If
Next i
End Sub
Private Sub setControl(flag As Boolean)
Command1.Visible = flag
Command2.Visible = flag
cmd_back.Visible = Not flag
End Sub
Private Sub setbound(flag As Boolean, Optional src As String)
For Each i In frmemp_data.Controls
If TypeOf i Is TextBox Then
If flag = True Then
i.DataSource = src
ElseIf Not IsNull(i.DataSource) Then
i.DataSource = ""
End If
End If
Next i
End Sub
Private Sub cmd_back_Click()
Data1.EOFAction = 0
setbound (False)
setVisible (False)
setControl (True)
Command3.Visible = False
End Sub
Private Sub Command1_Click()
Data1.EOFAction = 2
Data1.RecordSource = "select*from emp"
Data1.Refresh
setbound True, "Data1"
setVisible (True)
setControl (False)
End Sub
Private Sub Command2_Click()
Dim str As String
setVisible (True)
setControl (False)
setbound False
For Each i In frmemp_data.Controls
If TypeOf i Is TextBox Then
i.Text = ""
End If
Next i
Command3.Visible = True
Data1.RecordSource = ""
End Sub
Private Sub Command3_Click()
Dim str As String
str = "select*from employee"
If Text1(0).Text <> "" Then
str = str & "where Name="
str = str & Text1(0).Text & ""
Data1.Recordset.FindFirst str
If Data1.Recordset.EOF Then
MsgBox "No record found having name as" & Text1(0).Text
Else
Text1(1).Text = Data1.Recordset.Fields("address").Value
Text1(4).Text = Data1.Recordset.Fields("phone").Value
End If
ElseIf Text1(4).Text <> "" Then
str = str & "where phone="
str = str & "" & Text1(4).Text & ""
If Data1.Recordset.EOF Then
MsgBox "No record found having Phone as " & Text1(4).Text
Else
Text1(0).Text = Data1.Recordset.Fields("name").Value
Text1(1).Text = Data1.Recordset.Fields("address").Value
End If
End If
End Sub


(D) Errors :

If found any errors while running your VB program, or want to put your comment about any  program , please click Comment section , to post.

====================================================================
=========================================================

No comments: