Professional Documents
Culture Documents
Option Explicit
Public iWidth As Integer
Public iHeight As Integer
Public iLeft As Integer
Public iTop As Integer
Public bState As Boolean
Sub Reset()
With frmForm
.txtID.Value = ""
.txtName.Value = ""
.optMale.Value = False
.optFemale.Value = False
'Default Color
.txtID.BackColor = vbWhite
.txtName.BackColor = vbWhite
.txtCity.BackColor = vbWhite
.txtCountry.BackColor = vbWhite
.cmbDepartment.BackColor = vbWhite
'--------------------------------
.cmbDepartment.Clear
.cmbDepartment.RowSource = "Dynamic"
.cmbDepartment.Value = ""
.txtRowNumber.Value = ""
.txtCity.Value = ""
.txtCountry.Value = ""
Call Add_SearchColumn
ThisWorkbook.Sheets("Database").AutoFilterMode = False
ThisWorkbook.Sheets("SearchData").AutoFilterMode = False
ThisWorkbook.Sheets("SearchData").Cells.Clear
'-----------------------------------------------
.lstDatabase.ColumnCount = 9
.lstDatabase.ColumnHeads = True
.lstDatabase.ColumnWidths = "30,60,75,40,60,45,55,70,70"
.lstDatabase.RowSource = "Database!A2:I2"
End If
End With
End Sub
Module1 - 2
Sub Submit()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
iRow = [Counta(Database!A:A)] + 1
Else
iRow = frmForm.txtRowNumber.Value
End If
With sh
.Cells(iRow, 2) = frmForm.txtID.Value
.Cells(iRow, 3) = frmForm.txtName.Value
.Cells(iRow, 5) = frmForm.cmbDepartment.Value
.Cells(iRow, 6) = frmForm.txtCity.Value
.Cells(iRow, 7) = frmForm.txtCountry.Value
.Cells(iRow, 8) = Application.UserName
End With
End Sub
Sub Show_Form()
frmForm.Show
End Sub
Dim i As Long
Selected_List = 0
For i = 0 To frmForm.lstDatabase.ListCount - 1
Selected_List = i + 1
Exit For
End If
Next i
End Function
Sub Add_SearchColumn()
frmForm.EnableEvents = False
Module1 - 3
With frmForm.cmbSearchColumn
.Clear
.AddItem "All"
.Value = "All"
End With
frmForm.EnableEvents = True
frmForm.txtSearch.Value = ""
frmForm.txtSearch.Enabled = False
frmForm.cmdSearch.Enabled = False
End Sub
Sub SearchData()
Application.ScreenUpdating = False
Dim iColumn As Integer 'To hold the selected column number in Database sheet
Dim iDatabaseRow As Long 'To store the last non-blank row number available in Database sheet
Dim iSearchRow As Long 'To hold the last non-blank row number available in SearachData sheet
sColumn = frmForm.cmbSearchColumn.Value
sValue = frmForm.txtSearch.Value
shDatabase.AutoFilterMode = False
End If
Else
End If
shSearchData.Cells.Clear
shDatabase.AutoFilter.Range.Copy shSearchData.Range("A1")
Application.CutCopyMode = False
frmForm.lstDatabase.ColumnCount = 9
frmForm.lstDatabase.ColumnWidths = "30, 60, 75, 40, 60, 45, 55, 70, 70"
End If
Else
End If
shDatabase.AutoFilterMode = False
Application.ScreenUpdating = True
End Sub
ValidateEntries = True
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Print")
iEmployeeID = frmForm.txtID.Value
With frmForm
'Default Color
.txtID.BackColor = vbWhite
.txtName.BackColor = vbWhite
.txtCity.BackColor = vbWhite
.txtCountry.BackColor = vbWhite
.cmbDepartment.BackColor = vbWhite
'--------------------------------
End If
End If
End If
'Validating Gender
End If
MsgBox "Please select department name from drop-down.", vbOKOnly + vbInformation, "Dpar
tment"
ValidateEntries = False
.cmbDepartment.BackColor = vbRed
.cmbDepartment.SetFocus
Exit Function
End If
End If
End If
End With
End Function
ValidatePrintDetails = True
Module1 - 6
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Print")
iEmployeeID = frmForm.txtID.Value
With frmForm
'Default Color
.txtID.BackColor = vbWhite
.txtName.BackColor = vbWhite
.txtCity.BackColor = vbWhite
.txtCountry.BackColor = vbWhite
.cmbDepartment.BackColor = vbWhite
'--------------------------------
End If
End If
'Validating Gender
End If
MsgBox "Please select department name from drop-down.", vbOKOnly + vbInformation, "Dpar
tment"
ValidatePrintDetails = False
.cmbDepartment.BackColor = vbRed
.cmbDepartment.SetFocus
Exit Function
End If
End If
Module1 - 7
End If
End With
End Function
Sub Print_Form()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Print")
With frmForm
sh.Range("E5").Value = .txtID.Value
sh.Range("E7").Value = .txtName.Value
sh.Range("E11").Value = .cmbDepartment.Value
sh.Range("E13").Value = .txtCity.Value
sh.Range("E15").Value = .txtCountry.Value
End With
sh.PageSetup.PrintArea = "$B$2:$I$17"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Sub Maximize_Restore()
iWidth = frmForm.Width
iHeight = frmForm.Height
iTop = frmForm.Top
iLeft = frmForm.Left
With Application
Module1 - 8
.WindowState = xlMaximized
frmForm.Zoom = Int(.Width / frmForm.Width * 100)
frmForm.StartUpPosition = 0
frmForm.Left = .Left
frmForm.Top = .Top
frmForm.Width = .Width
frmForm.Height = .Height
End With
frmForm.cmdFullScreen.Caption = "Restore"
bState = True
Else
With Application
.WindowState = xlNormal
frmForm.Zoom = 100
frmForm.StartUpPosition = 0
frmForm.Left = iLeft
frmForm.Width = iWidth
frmForm.Height = iHeight
frmForm.Top = iTop
End With
bState = False
End If
End Sub