==================================================================================
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 "Area Code" using the Visual Data Manager with the following fields:
- Area Name
- City
- State
- Pin Code.
==========================
A) Program Design :
- We need to design a Database for this program.
Refer Linking to Database to create a table in Access. The created table (say,emp2) with the fields as per the question is given below :
(Here,db1 is the DataBase name, and emp2 is the Table name given) :
Field Name | Description | Data Type |
Area | Area Code | Text |
City | City | Text |
Pin | Pin Code | Number |
State | State | Text |
(B) Property(Controls Used) :
- 5 Labels
- 4 Text Boxes : Visible Property-False, Index Property from 0 to 3
- One Data Control (Database name db1 and RecordSource emp2)
- 4 Command Buttons with Captions : Main Menu (name:cmd_back,Visible Property-True), Data Transaction(name:command-1) , Search(name:command-2) and Find(name:command-3). Also,(Set the Visible Property as False for this 3 command Buttons)
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 = False 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 Set .i.DataSource = "" End If End If Next i End Sub |
Private Sub cmd_back_click() setbound (False) setVisible (False) setcontrol (True) Command3.Visible = False End Sub |
Private Sub Command1_Click() Data1.EOFAction = 2 setbound True, "Data1" setVisible (True) setcontrol (False) End Sub |
Private Sub Command2_Click() Dim str As String setVisible (True) Data1.Visible = False setcontrol (False) setbound False For Each i In frmemp_data.Controls If TypeOf i Is TextBox Then i.Text = "" End If Next i End Sub |
Private Sub Command3_Click() Dim str As String If Text2.Text <> "" Then str = " city=" & Text1.Text & "" Data1.Recordset.FindFirst Data1.Recordset.FindFirst str If Data1.Recordset.EOF Then MsgBox "Such City Not Found" Exit Sub Else If Text3.Text <> "" Then str = str & "and pin=" & Text1.Text & "" Data1.Recordset.FindFirst Data1.Recordset.FindFirst str If Not Data1.Recordset.EOF Then Text1.Text = Data1.Recordset.Fields("area").Value End If Text4.Text = Data1.Recordset.Fields("state").Value End If End If End Sub |
====================================================================
No comments:
Post a Comment