by Brandon (46 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 8th April 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
I modified my employee rolodex with more features, check it out!
API Declarations
Private Type Employee
Name As String
Department As String
Phone As String
Email As String
End Type
Private NameFound As String
Private udtName, udtDept, udtEmail, udtPhone As String
Private IndexCount As Integer
Private TotalRecords As Integer
Private EmployeeArray(1 To 100) As Employee
'put a common dialog control 6.0 from Project, Components on your form.
'create 3 file menus in the menu Handler, call them &File, &Edit, and &Tools.
'In the file menu, you will have 2 submenus, Call them &Read File and &Exit
'In the Edit menu, you will have 1 submenu,Call it &Add Record.
'In the Tools menu, you will have 1 submenu, call it &Search for Records
'use 4 labels with the following captions: Employee Name, Department, Email,
'and Phone.
'place 6 text boxes on your form. 4 of these text boxes will be placed next
'to each label. The other two text boxes display the current record and the
'total number of records in the database.
'use the following names in the properties window for the first 4 textboxes:
'txtEmpName, txtDepartment, txtEmail, txtPhone.
'For the other 2 textboxes call them: txtCurrentRecord, txtTotalRecords
'in front of the txtCurrentRecord textbox, place a label and for its caption
'call it "Record"
'Before the txtTotalRecords textbox, use another label and call its Caption "of"
'use 5 command buttons. Use appropriate captions and change the names in the propery window to the following: cmdCancel, cmdFirstRec, cmdPrevious, cmdNextRecord, and cmdLastRec.
'make sure all code is placed in the correct procedures and you have used the correct names.
'In addition, create a text file. This is where all your data will come from. give it any name you wish, but enter this data in it exactly as shown below.
Sample Data:
"John Smith", "Math", "[email protected]", "456-8989"
"Wally Rice", "English", "[email protected]", "340-8989"
"Linda Cooke", "Science", "[email protected]", "435-9090"
'When you first run the program, you will need execute the read file choice
'on your file menu and browse out to your input file, once you do this the
'data will appear on your form!
'Also, I am in the process of working on code that deletes records..I can delete the record on the actual form, but still having problems removing the
exact record from the input file, if you have any ideas or suggestions, email me at [email protected].
'here's the code you need, have fun!
'************Main Program***************
'Program: An employee rolodex database
'Modified: August 4, 2001
'***************************************
Private Sub cmdCancel_Click()
'cancel add procedure
Call cmdFirstRec_Click
mnuEditAddRec.Caption = "&Add Record"
ShowButtons
cmdCancel.Visible = False
End Sub
Private Sub cmdFirstRec_Click()
'show first record
'set index to first record
IndexCount = 1
PrintRecords
End Sub
Private Sub cmdLastRec_Click()
'show last record
IndexCount = TotalRecords
PrintRecords
End Sub
Private Sub cmdNextRecord_Click()
'view next record
IndexCount = IndexCount + 1
If EmployeeArray(IndexCount).Name = vbNullString Then
MsgBox "You are at the last record", vbInformation, "Last Record"
IndexCount = IndexCount - 1
Else
Call PrintRecords
End If
End Sub
Private Sub cmdPrevious_Click()
'scroll to previous record
If IndexCount <= 1 Then
MsgBox "You are on the first record", vbInformation, "First Record"
Else
IndexCount = IndexCount - 1
Call PrintRecords
End If
End Sub
Private Sub PrintRecords()
'print array records
txtEmpName.Text = EmployeeArray(IndexCount).Name
txtDepartment.Text = EmployeeArray(IndexCount).Department
txtEmail.Text = EmployeeArray(IndexCount).Email
txtPhone.Text = EmployeeArray(IndexCount).Phone
cmdFirstRec.Enabled = True
cmdLastRec.Enabled = True
RecordDisplay
End Sub
Private Sub Form_Load()
cmdFirstRec.Enabled = False
cmdLastRec.Enabled = False
cmdPrevious.Enabled = False
cmdLastRec.Enabled = False
cmdCancel.Visible = False
cmdNextRecord.Enabled = False
mnuEdit.Enabled = False
mnuTools.Enabled = False
End Sub
Sub RecordDisplay()
txtCurrentRecord.Text = IndexCount
txtTotalRecords.Text = TotalRecords
End Sub
Private Sub mnuEditAddRec_Click()
'add a new record
HideButtons
cmdCancel.Visible = True
If mnuEditAddRec.Caption = "&Add Record" Then
Call ClearText
mnuEditAddRec.Caption = "&Save Record"
Else
TotalRecords = TotalRecords + 1
EmployeeArray(TotalRecords).Name = txtEmpName.Text
EmployeeArray(TotalRecords).Department = txtDepartment.Text
EmployeeArray(TotalRecords).Email = txtEmail.Text
EmployeeArray(TotalRecords).Phone = txtPhone.Text
Open CommonDialog1.FileName For Append As #1
Write #1, txtEmpName, txtDepartment, txtEmail, txtPhone
Close #1
cmdCancel.Visible = False
mnuEditAddRec.Caption = "&Add Record"
cmdFirstRec_Click
ShowButtons
End If
End Sub
Private Sub mnuFileExit_Click()
'exit program
Dim intResponse As Integer
intResponse = MsgBox("Do you wish to exit?", vbYesNo + vbQuestion, "Exit System")
If intResponse = vbYes Then
Unload Me
End If
End Sub
Private Sub mnuFileRead_Click()
'get input from file
CommonDialog1.ShowOpen 'show all files
Open CommonDialog1.FileName For Input As #1
IndexCount = 1 'initialize for first record in array
Do While Not EOF(1)
'get data from text file
Input #1, udtName, udtDept, udtEmail, udtPhone
EmployeeArray(IndexCount).Name = udtName
EmployeeArray(IndexCount).Department = udtDept
EmployeeArray(IndexCount).Email = udtEmail
EmployeeArray(IndexCount).Phone = udtPhone
IndexCount = IndexCount + 1 'increment counter
TotalRecords = TotalRecords + 1
Loop
Close #1 'close input file
IndexCount = 1 'reset counter
Call PrintRecords 'procedure call
cmdPrevious.Enabled = True 'enable controls
cmdNextRecord.Enabled = True
mnuFileRead.Enabled = False
mnuEdit.Enabled = True
mnuTools.Enabled = True
End Sub
Private Sub mnuToolsSearchRecords_Click()
Dim udtName, udtDept, udtEmail, udtPhone As String
'find the record
Dim strCriteria As String
Dim blnNotFound As Boolean
strCriteria = InputBox("Enter the name of the person you are looking for", "Search")
Open CommonDialog1.FileName For Input As #1
blnNotFound = True
Do Until EOF(1)
Input #1, udtName, udtDept, udtEmail, udtPhone
If strCriteria = udtName Then
txtEmpName.Text = udtName
txtDepartment.Text = udtDept
txtEmail.Text = udtEmail
txtPhone.Text = udtPhone
MsgBox "Record was found!", vbExclamation, "Record found"
blnNotFound = False
Exit Do
Exit Sub
End If
Loop
Close #1
If blnNotFound Then
MsgBox "Record was not found!", vbCritical, "Invalid Record"
End If
End Sub
Sub ClearText()
txtEmpName.Text = ""
txtDepartment.Text = ""
txtEmail.Text = ""
txtPhone.Text = ""
txtEmpName.SetFocus
End Sub
Sub HideButtons()
cmdPrevious.Visible = False
cmdNextRecord.Visible = False
cmdFirstRec.Visible = False
cmdLastRec.Visible = False
End Sub
Sub ShowButtons()
cmdPrevious.Visible = True
cmdNextRecord.Visible = True
cmdFirstRec.Visible = True
cmdLastRec.Visible = True
End Sub
No comments have been posted about I modified my employee rolodex with more features, check it out!. Why not be the first to post a comment about I modified my employee rolodex with more features, check it out!.