Here is the code for thew userform.
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' This is the command to close this userform and open up the main
' start menu.
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Private Sub CmdMenu_Click()
Unload Me
Start.Show
End Sub
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' This is the command to save the document and leave the form open
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Private Sub CmdSave_Click()
If MsgBox("Do you want to continue ?", vbOKCancel, _
"Job Index - Save") = vbCancel Then Exit Sub
Dim WB As Workbook
For Each WB In Workbooks
WB.Save
Next WB
Application.StatusBar = "All Workbooks Saved."
End Sub
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' This is the command to save the document and EXIT the form
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Private Sub CmdSaveExit_Click()
If MsgBox("Do you want to continue ?", vbOKCancel, _
"Job Index - Save and Exit") = vbCancel Then Exit Sub
Application.Quit
' MsgBox "Do you want to save and exit?", vbExclamation, "Job Index"
' Answer = MsgBox("Do you want to continue ?", vbYesNo)
' messagebox with YES- and NO-buttons,
' the result is an integer, the constants are named vbYes and vbNo.
ThisWorkbook.Close SaveChanges:=True
End Sub
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' This is the command to clear the form and leave it open
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Private Sub cmdClearForm_Click()
' End Sub
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' This is the command to CANCEL the form and close it
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Private Sub CmdCancel_Click()
If MsgBox("Do you want to continue? This will close without adding to
database or saving.", vbOKCancel, _
"Job Index - Close") = vbCancel Then Exit Sub
Unload Me
' MsgBox "Do you want to cancel?", vbExclamation, "Job Index"
End Sub
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' This is the command to complete the form and leave it open
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Private Sub cmdOK_Click()
Dim RowCount As Long
Dim ctl As Control
' Checks User inputs. This series of commands checks that the user inputs
' the required details in the boxes
' Date Received
If Me.TxtDateRecd.Value = "" Then
MsgBox "The received date box must be completed.", vbExclamation, "Job
Index"
Me.TxtDateRecd.SetFocus
Exit Sub
End If
' Correcting date received details using date format
If Not IsDate(Me.TxtDateRecd.Value) Then
MsgBox "The received date box must contain a date in the DD/MM/YY
format.", vbExclamation, "Job Index"
Me.TxtDateRecd.SetFocus
Exit Sub
End If
' This is for a reference Number
If Me.TxtRefNos.Value = "" Then
MsgBox "The Reference number of the job must be completed.",
vbExclamation, "Job Index"
Me.TxtRefNos.SetFocus
Exit Sub
End If
' Description of job
If Me.TxtDesc.Value = "" Then
MsgBox "The description of the job box must be completed.",
vbExclamation, "Job Index"
Me.TxtDesc.SetFocus
Exit Sub
End If
' Location of job
If Me.TxtLoc.Value = "" Then
MsgBox "The description of the location box must be completed.",
vbExclamation, "Job Index"
Me.TxtLoc.SetFocus
Exit Sub
End If
' Workers details using works number (3 digits) only
If Me.TxtWorker.Value = "" Then
MsgBox "The workers works number must be completed.", vbExclamation,
"Job Index"
Me.TxtWorker.SetFocus
Exit Sub
End If
' Correcting workers details using works number (3 digits) only
If Not IsNumeric(Me.TxtWorkerr.Value) Then
MsgBox "The workers works number must be completed using 3 digits.",
vbExclamation, "Job Index"
Me.TxtWorker.SetFocus
Exit Sub
End If
' Date Due
If Me.TxtDue.Value = "" Then
MsgBox "The due date box must be completed.", vbExclamation, "Job Index"
Me.TxtDue.SetFocus
Exit Sub
End If
' Correcting date due details using date format
If Not IsDate(Me.TxtDue.Value) Then
MsgBox "The due date box must contain a date in the DD/MM/YY format.",
vbExclamation, "Job Index"
Me.TxtDue.SetFocus
Exit Sub
End If
' Write data to worksheet
RowCount = Worksheets("2007").Range("B5").CurrentRegion.Rows.Count
With Worksheets("2007").Range("B5")
.Offset(RowCount, 1).Value = Me.TxtDateRecd.Value
.Offset(RowCount, 0).Value = Me.TxtRefNos.Value
.Offset(RowCount, 2).Value = Me.TxtDesc.Value
.Offset(RowCount, 4).Value = Me.TxtLoc.Value
.Offset(RowCount, 5).Value = Me.CboStation.Value
.Offset(RowCount, 6).Value = Me.TxtDue.Value
.Offset(RowCount, 21).Value = Me.TxtWorker.Value
End With
' This command is for selecting the type of job via a radio button
' By default it will insert other
If OptSBD = True Then
ActiveCell.Offset(0, 3).Value = "A Type"
ElseIf OptALO = True Then
ActiveCell.Offset(0, 3).Value = "B Type"
ElseIf OptCCTV = True Then
ActiveCell.Offset(0, 3).Value = "C Type"
ElseIf OptComm = True Then
ActiveCell.Offset(0, 3).Value = "D Type"
ElseIf OptDom = True Then
ActiveCell.Offset(0, 3).Value = "E Type"
ElseIf OptCPcom = True Then
ActiveCell.Offset(0, 3).Value = "F Type"
ElseIf OptCPdom = True Then
ActiveCell.Offset(0, 3).Value = "G Type"
Else
ActiveCell.Offset(0, 3).Value = "OTHer"
End If
' Call UserForm_Initialize
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub
Private Sub UserForm_Initialize()
TxtDateRecd.Value = ""
TxtRefNos.Value = ""
TxtLoc.Value = ""
TxtDue.Value = ""
TxtWorker.Value = ""
CboStation.Value = ""
TxtDateRecd.SetFocus
End Sub