Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Main userform
- Private Sub UserForm_Initialize()
- InitializeForm
- ' Sets object defaults
- cb_Extension = False
- txt_Extension.Visible = False
- label_ExtendTime.Visible = False
- CompassFrame.Visible = False
- FireExtFrame.Visible = False
- FirstAidFrame.Visible = False
- WBFrame.Visible = False
- DualsFrame.Visible = False
- opt_Maint.Value = True
- ' Hide box_Duals content control by default
- Dim boxDuals As ContentControl
- Set boxDuals = ActiveDocument.SelectContentControlsByTitle("box_Duals").item(1)
- If Not boxDuals Is Nothing Then
- boxDuals.Range.Font.Hidden = True
- End If
- End Sub
- Private Sub InitializeForm()
- ' Arrays for combo box values
- Dim inspectionTypes As Variant
- inspectionTypes = Array("75 Hour inspection", "150 Hour inspection", "300 Hour inspection", _
- "1500 Hour inspection", "6000 Hour inspection", "100 Hour inspection", _
- "500 Hour inspection", "1000 Hour inspection")
- Dim dualNames As Variant
- dualNames = Array("Dave J", "Dave M", "Steve", "Peter", "Pierre", "Marc", "Ken")
- ' Populate BottomAddsList
- Dim bottomAddsItems As Variant
- bottomAddsItems = Array("Engine leak check required after first flight", _
- "Aircraft released conditional to satisfactory 1500hr inspection / engine break in test flight ", _
- "Aircraft released conditional to satisfactory test flight due to fuel system adjustments carried out", _
- "Propeller torque check required after first flight and after first 25hrs to not exceed X hrs TTAF", _
- "Initial 5hr alternator belt tension check required to not exceed Y hrs ", _
- "Initial 25hr engine operation inspection required to not exceed X hrs TTAF", _
- "25 hour propeller retorque due at X hrs TTAF")
- 'Allows multiselect for bottom items
- Dim item As Variant
- For Each item In bottomAddsItems
- Me.BottomAddsList.AddItem item
- Next item
- Me.BottomAddsList.MultiSelect = fmMultiSelectMulti
- ' Populate inspection type combo box
- For Each item In inspectionTypes
- Me.cmb_InspectionType.AddItem item
- Next item
- Me.cmb_InspectionType.Value = "75 Hour inspection" ' Default value
- ' Populate duals combo box
- For Each item In dualNames
- Me.cmb_Duals.AddItem item
- Next item
- ' Populate recurring defect combo box
- With Me.cmb_RecurDef
- .AddItem "No"
- .AddItem "Yes"
- .Value = "No" ' Default value
- End With
- End Sub
- Public Function BuildWPFull() As String
- Dim regPart As String
- regPart = Right(txt_Reg.text, 3)
- BuildWPFull = UCase(regPart & "-" & txt_WPYear.text & "-" & txt_WPNumber.text)
- End Function
- 'This function displays shortened names in the Duals drop down menu, and prints the full name W/ license number on the release
- Private Function GetFullName(shortName As String) As String
- Select Case shortName
- Case "Dave J"
- GetFullName = "David Jones 450901"
- Case "Dave M"
- GetFullName = "Dave Melanson 414817"
- Case "Steve"
- GetFullName = "Stephen Humphrey 811691"
- Case "Peter"
- GetFullName = "Peter Roberts 451738"
- Case "Pierre"
- GetFullName = "Pierre Damboise 451004"
- Case "Marc"
- GetFullName = "Marc Vautour 414479"
- Case "Ken"
- GetFullName = "Ken Branch 415274"
- Case Else
- GetFullName = shortName
- End Select
- End Function
- 'This controls visibility of boxes on userform based on maintenance type being selected
- Private Sub SetVisibility(ByVal inspectionTypeVisible As Boolean, _
- ByVal snagEntryVisible As Boolean, _
- ByVal extensionVisible As Boolean)
- cmb_InspectionType.Visible = inspectionTypeVisible
- label_InspectionType.Visible = inspectionTypeVisible
- cb_Extension.Visible = extensionVisible
- txt_SnagEntry.Visible = snagEntryVisible
- label_SnagEntry.Visible = snagEntryVisible
- label_SnagRectification.Visible = snagEntryVisible
- txt_SnagRect.Visible = snagEntryVisible
- End Sub
- Private Sub opt_Snag_Click()
- SetVisibility False, True, False
- UpdateContentBoxesVisibility
- End Sub
- Private Sub opt_Maint_Click()
- SetVisibility True, False, True
- UpdateContentBoxesVisibility
- End Sub
- Private Sub opt_Both_Click()
- SetVisibility True, True, True
- UpdateContentBoxesVisibility
- End Sub
- Private Sub UpdateContentBoxesVisibility()
- Dim ccSnag As ContentControl
- Dim ccMaint As ContentControl
- Set ccSnag = ActiveDocument.SelectContentControlsByTag("box_Snag")(1)
- Set ccMaint = ActiveDocument.SelectContentControlsByTag("box_Maint")(1)
- If opt_Snag.Value Then
- ccSnag.Range.Font.Hidden = False
- ccMaint.Range.Font.Hidden = True
- ElseIf opt_Maint.Value Then
- ccSnag.Range.Font.Hidden = True
- ccMaint.Range.Font.Hidden = False
- ElseIf opt_Both.Value Then
- ccSnag.Range.Font.Hidden = False
- ccMaint.Range.Font.Hidden = False
- End If
- End Sub
- Private Sub btnSubmit_Click()
- Dim doc As Document
- Dim WPFull As String
- WPFull = BuildWPFull()
- Set doc = Application.ActiveDocument
- Call UpdateContentControls
- If opt_Snag.Value = True Or opt_Both.Value = True Then
- UpdateSnagContent "Snag: " & txt_SnagEntry.Value, "text_SnagTitle"
- UpdateSnagContent txt_SnagRect.Value, "text_SnagRectify"
- End If
- UpdateMaintHeader doc, cmb_InspectionType.Value, cb_Extension.Value
- Dim ExtensionChecked As Boolean
- Dim AddWorkChecked As Boolean
- Dim inspectionType As String
- ExtensionChecked = cb_Extension.Value
- AddWorkChecked = cb_Addwork.Value
- inspectionType = cmb_InspectionType.Value
- UpdateMaintenanceBody ExtensionChecked, inspectionType, AddWorkChecked
- If cb_Compass.Value = True Then
- UpdateCompassHeadings
- End If
- Call AddBottomEntries(text25.Value, text5.Value, txtCustomEntry.Value)
- End Sub
- Private Sub UpdateContentControls()
- Dim cc As ContentControl
- Dim WPFull As String
- WPFull = BuildWPFull()
- For Each cc In ActiveDocument.ContentControls
- Select Case cc.tag
- Case "Text_Reg"
- cc.Range.text = UCase(txt_Reg.text)
- Case "Text_Date"
- cc.Range.text = txt_Date.text
- Case "Doc_RecDef"
- cc.Range.text = cmb_RecurDef.Value
- Case "Text_TTAF"
- cc.Range.text = txt_TTAF.text & " Hrs"
- Case "Text_WPFull"
- cc.Range.text = WPFull
- cc.Range.Font.Bold = True
- Case "Doc_InspectionType"
- cc.Range.text = cmb_InspectionType.Value
- End Select
- Next cc
- End Sub
- Private Sub cb_Compass_Click()
- CompassFrame.Visible = cb_Compass.Value
- Dim doc As Document
- Dim cc As ContentControl
- Dim tbl As Table
- Dim ccInTable As ContentControl
- Dim tblRange As Range
- Set doc = ActiveDocument
- For Each cc In doc.ContentControls
- If cc.tag = "box_Compass" Then
- If cc.Range.Tables.Count > 0 Then
- Set tbl = cc.Range.Tables(1)
- Set tblRange = tbl.Range
- Exit For
- End If
- End If
- Next cc
- If Not tbl Is Nothing Then
- If cb_Compass.Value Then
- tblRange.Font.Hidden = False
- For Each ccInTable In doc.ContentControls
- If ccInTable.Range.Start >= tblRange.Start And ccInTable.Range.End <= tblRange.End Then
- ccInTable.Range.Font.Hidden = False
- End If
- Next ccInTable
- Else
- tblRange.Font.Hidden = True
- For Each ccInTable In doc.ContentControls
- If ccInTable.Range.Start >= tblRange.Start And ccInTable.Range.End <= tblRange.End Then
- ccInTable.Range.Font.Hidden = True
- End If
- Next ccInTable
- End If
- End If
- End Sub
- Private Sub UpdateCompassHeadings()
- Dim cc As ContentControl
- Dim userFormControl As MSForms.Control
- Dim contentControlName As String
- Dim userFormTextboxName As String
- For Each cc In ActiveDocument.ContentControls
- Select Case cc.tag
- Case "text_North", "text_30", "text_60", "text_East", "text_120", _
- "text_150", "text_South", "text_210", "text_240", _
- "text_West", "text_300", "text_330"
- userFormTextboxName = Replace(cc.tag, "text_", "txt")
- Set userFormControl = Me.Controls(userFormTextboxName)
- If Not userFormControl Is Nothing Then
- cc.Range.text = UCase(userFormControl.Value)
- End If
- End Select
- Next cc
- End Sub
- Private Sub cb_Extension_Click()
- label_ExtendTime.Visible = cb_Extension.Value
- txt_Extension.Visible = cb_Extension.Value
- End Sub
- Private Sub cb_FireExt_Click()
- FireExtFrame.Visible = cb_FireExt.Value
- End Sub
- Private Sub cb_FirstAidKit_Click()
- FirstAidFrame.Visible = cb_FirstAidKit.Value
- End Sub
- Private Sub cb_WB_Click()
- WBFrame.Visible = cb_WB.Value
- End Sub
- Private Sub AddBottomEntries(userNumberX As String, userNumberY As String, customEntry As String)
- Dim i As Integer
- Dim selectedItem As String
- For i = 0 To BottomAddsList.ListCount - 1
- If BottomAddsList.Selected(i) Then
- selectedItem = Replace(Replace(BottomAddsList.List(i), "X", userNumberX), "Y", userNumberY)
- AddTextToDocument "*** " & Trim(selectedItem) & " ***", True
- End If
- Next i
- If customEntry <> "" Then
- AddTextToDocument "*** " & Trim(customEntry) & " ***", True
- End If
- End Sub
- 'Adds the notes to the bottom and centeres it
- Private Sub AddTextToDocument(text As String, alignCenter As Boolean)
- Selection.EndKey Unit:=wdStory
- Selection.TypeParagraph
- If alignCenter Then
- Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
- End If
- Selection.TypeText text:=text & vbCrLf
- End Sub
- Private Sub cb_Duals_Click()
- Dim doc As Document
- Set doc = ActiveDocument
- DualsFrame.Visible = cb_Duals.Value
- Dim boxDuals As ContentControl
- Set boxDuals = doc.SelectContentControlsByTitle("box_Duals").item(1)
- If Not boxDuals Is Nothing Then
- If cb_Duals.Value Then
- boxDuals.Range.Font.Hidden = False
- Else
- boxDuals.Range.Font.Hidden = True
- End If
- End If
- End Sub
- Private Sub cb_DualTCs_Click()
- DualsUserform.Show
- End Sub
- Private Sub cmb_Duals_Change()
- Dim fullName As String
- Dim cc As ContentControl
- fullName = GetFullName(cmb_Duals.Value)
- For Each cc In ActiveDocument.ContentControls
- If cc.tag = "text_PerfDual" Then
- cc.Range.text = fullName
- Exit For
- End If
- Next cc
- End Sub
- 'Duals userform
- Option Explicit
- Private counter As Integer
- Private Sub UserForm_Initialize()
- counter = 1
- End Sub
- Private Sub cb_AddRow_Click()
- counter = counter + 1
- Dim lastControlBox As MSForms.TextBox
- Dim lastTCBox As MSForms.TextBox
- Set lastControlBox = Me.Controls("txt_DualControl" & (counter - 1))
- Set lastTCBox = Me.Controls("txt_DualTC" & (counter - 1))
- Dim newControlBox As MSForms.TextBox
- Dim newTCBox As MSForms.TextBox
- Set newControlBox = Me.Controls.Add("Forms.TextBox.1", "txt_DualControl" & counter)
- With newControlBox
- .Left = lastControlBox.Left
- .Top = lastControlBox.Top + lastControlBox.Height + 5
- .Width = lastControlBox.Width
- .Height = lastControlBox.Height
- End With
- Set newTCBox = Me.Controls.Add("Forms.TextBox.1", "txt_DualTC" & counter)
- With newTCBox
- .Left = lastTCBox.Left
- .Top = lastTCBox.Top + lastTCBox.Height + 5
- .Width = lastTCBox.Width
- .Height = lastTCBox.Height
- End With
- Dim cc As ContentControl
- Dim tbl As Table
- For Each cc In ActiveDocument.ContentControls
- If cc.tag = "box_DualTCs" Then
- Set tbl = cc.Range.Tables(1)
- tbl.Rows.Add
- Exit For
- End If
- Next cc
- End Sub
- Public Sub TransferDataToTable()
- Dim cc As ContentControl
- Dim tbl As Table
- Dim i As Integer
- For Each cc In ActiveDocument.ContentControls
- If cc.tag = "box_DualTCs" Then
- Set tbl = cc.Range.Tables(1)
- For i = 1 To counter
- Dim controlBox As MSForms.TextBox
- Dim tcBox As MSForms.TextBox
- Set controlBox = Me.Controls("txt_DualControl" & i)
- Set tcBox = Me.Controls("txt_DualTC" & i)
- tbl.Rows(i).Cells(1).Range.text = controlBox.text
- tbl.Rows(i).Cells(2).Range.text = tcBox.text
- Next i
- Exit For
- End If
- Next cc
- End Sub
- Private Sub cb_AddData_Click()
- TransferDataToTable
- Me.Hide
- End Sub
- 'Formatting module
- Public Sub ApplyTextFormatToText(ByRef targetRange As Range, _
- ByVal textToFormat As String, _
- Optional ByVal FontName As String = "Times New Roman", _
- Optional ByVal FontSize As Single = 8, _
- Optional ByVal Bold As Boolean = True, _
- Optional ByVal Italic As Boolean = False, _
- Optional ByVal Underline As Boolean = False, _
- Optional ByVal FontColor As Long = wdColorAutomatic, _
- Optional ByVal Alignment As WdParagraphAlignment = wdAlignParagraphLeft)
- ' Check if targetRange is valid
- If targetRange Is Nothing Or targetRange.text = "" Then Exit Sub
- ' Find and format the text
- With targetRange.Find
- .text = textToFormat
- .MatchCase = False
- .MatchWholeWord = False
- If .Execute Then
- With .Parent
- ' Apply font properties
- With .Font
- .Name = FontName
- .Size = FontSize
- .Bold = Bold
- .Italic = Italic
- .Underline = IIf(Underline, wdUnderlineSingle, wdUnderlineNone)
- .Color = FontColor
- End With
- ' Apply paragraph alignment
- .ParagraphFormat.Alignment = Alignment
- End With
- End If
- End With
- End Sub
- ' Helper function to add section content with proper formatting
- Public Sub AddFormattedSection(ByRef content As String, ByVal mainText As String, ByRef subItems() As String, ByVal WPFull As String)
- content = content & vbCrLf & mainText & " REF WP " & WPFull
- Dim subItem As Variant
- For Each subItem In subItems
- If subItem <> "" Then
- content = content & vbCrLf & subItem
- End If
- Next subItem
- End Sub
- 'Updatting content module
- Public Sub UpdateSnagContent(ByVal textToInsert As String, ByVal contentTag As String)
- Dim doc As Document
- Dim cc As ContentControl
- ' Get the active document
- Set doc = ActiveDocument
- ' Update content if conditions are met (for SnagRect)
- If contentTag = "text_SnagRectify" Then
- If Not (ReleaseHub.opt_Snag.Value = True Or ReleaseHub.opt_Both.Value = True) Then
- Exit Sub
- End If
- End If
- ' Find and update the content control
- For Each cc In doc.ContentControls
- If cc.tag = contentTag Then
- cc.Range.text = textToInsert
- Exit For
- End If
- Next cc
- End Sub
- Public Sub UpdateMaintHeader(doc As Word.Document, inspectionType As String, isExtension As Boolean)
- Dim cc As Word.ContentControl
- Dim maintTitleText As String
- 'Sub is good, only updates header.
- ' Find the content control by tag
- For Each cc In doc.ContentControls
- If cc.tag = "text_MaintTitle" Then Exit For
- Next cc
- If cc Is Nothing Then Exit Sub ' Exit silently if not found
- ' Determine the text to set based on isExtension value
- If isExtension Then
- maintTitleText = "Maintenance: " & inspectionType & " extension to be carried out"
- Else
- maintTitleText = "Maintenance: " & inspectionType & " to be carried out"
- End If
- ' Update the content control text
- cc.Range.text = maintTitleText
- End Sub
- ' Helper function to format each paragraph with proper indentation and styling
- Private Sub FormatParagraph(ByVal para As Paragraph, ByVal isMainEntry As Boolean, ByVal isBold As Boolean)
- With para.Range
- .Font.Size = 8
- .Font.Bold = isBold
- .ListFormat.ListLevelNumber = IIf(isMainEntry, 1, 2)
- End With
- End Sub
- ' Function to handle Fire Extinguisher section
- Private Function GetFireExtinguisherContent(ByVal frm As ReleaseHub, ByVal WPFull As String) As String
- If Not frm.cb_FireExt.Value Then Exit Function
- Dim content As String
- Dim subItems(2) As String
- subItems(0) = "Next annual inspection due " & frm.txt_FireAnnual.Value
- subItems(1) = "Next 6 year inspection due " & frm.txt_Fire6Year.Value
- subItems(2) = "Next 12 year hydrostatic inspection due " & frm.txt_Fire12Year.Value
- AddFormattedSection content, "Fire extinguisher annual inspection carried out", subItems, WPFull
- GetFireExtinguisherContent = content
- End Function
- ' Function to handle First Aid Kit section
- Private Function GetFirstAidKitContent(ByVal frm As ReleaseHub, ByVal WPFull As String) As String
- If Not frm.cb_FirstAidKit.Value Then Exit Function
- Dim content As String
- Dim subItems(0) As String
- subItems(0) = "Next annual inspection due " & frm.txt_FirstAidAnnual.Value
- AddFormattedSection content, "First aid kit annual inspection carried out", subItems, WPFull
- GetFirstAidKitContent = content
- End Function
- ' Function to handle Weight and Balance section
- Private Function GetWeightBalanceContent(ByVal frm As ReleaseHub, ByVal WPFull As String) As String
- If Not frm.cb_WB.Value Then Exit Function
- Dim content As String
- Dim subItems(2) As String
- subItems(0) = "New aircraft empty weight: " & frm.txt_WBEW.Value & " Lbs"
- subItems(1) = "New aircraft C of G arm: " & frm.txt_WBCoG.Value & " inches"
- subItems(2) = "New aircraft moment: " & frm.txt_WBMoment.Value
- AddFormattedSection content, "Weight and balance amendment # " & frm.txt_WBAmend.Value & " now in effect.", subItems, WPFull
- GetWeightBalanceContent = content
- End Function
- ' Main procedure
- Public Sub UpdateMaintenanceBody(ByVal ExtensionValue As Boolean, ByVal InspectionTypeValue As String, ByVal AddWorkChecked As Boolean)
- Dim doc As Document
- Set doc = ActiveDocument
- Dim frm As ReleaseHub
- Set frm = ReleaseHub
- Dim WPFull As String
- WPFull = frm.BuildWPFull
- ' Get the content control
- Dim ccRange As Range
- Set ccRange = doc.SelectContentControlsByTag("text_MaintBody")(1).Range
- ' Build the initial content
- Dim content As String
- If ExtensionValue Then
- content = InspectionTypeValue & " and all related tasks in WP " & WPFull & _
- " extended 10 hours and now due at " & frm.txt_Extension.Value & " Hrs"
- Else
- content = InspectionTypeValue & " carried out REF WP " & WPFull
- End If
- ' Add additional work line if checked
- If AddWorkChecked Then
- content = content & vbCrLf & "Additional work carried out REF WP " & WPFull
- End If
- ' Add specialized sections
- content = content & GetFireExtinguisherContent(frm, WPFull)
- content = content & GetFirstAidKitContent(frm, WPFull)
- content = content & GetWeightBalanceContent(frm, WPFull)
- ' Add compass swing if checked
- If frm.cb_Compass.Value Then
- content = content & vbCrLf & "Compass swing carried out REF WP " & WPFull & ". New headings below."
- End If
- ' Set the content
- ccRange.text = content
- ' Format the content
- With ccRange
- .Font.Size = 8
- .ListFormat.RemoveNumbers
- .ListFormat.ApplyListTemplateWithLevel _
- ListTemplate:=ListGalleries(wdNumberGallery).ListTemplates(1), _
- ContinuePreviousList:=False, _
- ApplyTo:=wdListApplyToWholeList, _
- DefaultListBehavior:=wdWord10ListBehavior
- ' Format each paragraph
- For Each mainPara In .Paragraphs
- Dim isMainEntry As Boolean
- Dim isBold As Boolean
- ' Determine formatting based on content
- If InStr(mainPara.Range.text, "Weight and balance") > 0 Then
- isMainEntry = True
- isBold = True
- ElseIf InStr(mainPara.Range.text, "New aircraft") > 0 Then
- isMainEntry = False
- isBold = True
- ElseIf InStr(mainPara.Range.text, "Next") > 0 Then
- isMainEntry = False
- isBold = False
- Else
- isMainEntry = True
- isBold = False
- End If
- FormatParagraph mainPara, isMainEntry, isBold
- Next mainPara
- End With
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment