JustJoe21

Untitled

Dec 28th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.70 KB | None | 0 0
  1. 'Main userform
  2. Private Sub UserForm_Initialize()
  3. InitializeForm
  4. ' Sets object defaults
  5. cb_Extension = False
  6. txt_Extension.Visible = False
  7. label_ExtendTime.Visible = False
  8. CompassFrame.Visible = False
  9. FireExtFrame.Visible = False
  10. FirstAidFrame.Visible = False
  11. WBFrame.Visible = False
  12. DualsFrame.Visible = False
  13. opt_Maint.Value = True
  14.  
  15. End Sub
  16.  
  17. Private Sub InitializeForm()
  18. ' Arrays for combo box values
  19. Dim inspectionTypes As Variant
  20. inspectionTypes = Array("75 Hour inspection", "150 Hour inspection", "300 Hour inspection", _
  21. "1500 Hour inspection", "6000 Hour inspection", "100 Hour inspection", _
  22. "500 Hour inspection", "1000 Hour inspection")
  23.  
  24. Dim dualNames As Variant
  25. dualNames = Array("Dave J", "Dave M", "Steve", "Peter", "Pierre", "Marc", "Ken")
  26.  
  27. ' Populate BottomAddsList
  28. Dim bottomAddsItems As Variant
  29. bottomAddsItems = Array("Engine leak check required after first flight", _
  30. "Aircraft released conditional to satisfactory 1500hr inspection / engine break in test flight ", _
  31. "Aircraft released conditional to satisfactory test flight due to fuel system adjustments carried out", _
  32. "Propeller torque check required after first flight and after first 25hrs to not exceed X hrs TTAF", _
  33. "Initial 5hr alternator belt tension check required to not exceed Y hrs ", _
  34. "Initial 25hr engine operation inspection required to not exceed X hrs TTAF", _
  35. "25 hour propeller retorque due at X hrs TTAF")
  36.  
  37. 'Allows multiselect for bottom items
  38. Dim item As Variant
  39. For Each item In bottomAddsItems
  40. Me.BottomAddsList.AddItem item
  41. Next item
  42. Me.BottomAddsList.MultiSelect = fmMultiSelectMulti
  43.  
  44. ' Populate inspection type combo box
  45. For Each item In inspectionTypes
  46. Me.cmb_InspectionType.AddItem item
  47. Next item
  48. Me.cmb_InspectionType.Value = "75 Hour inspection" ' Default value
  49.  
  50. ' Populate duals combo box
  51. For Each item In dualNames
  52. Me.cmb_Duals.AddItem item
  53. Next item
  54.  
  55. ' Populate recurring defect combo box
  56. With Me.cmb_RecurDef
  57. .AddItem "No"
  58. .AddItem "Yes"
  59. .Value = "No" ' Default value
  60. End With
  61. End Sub
  62. Public Function BuildWPFull() As String
  63. Dim regPart As String
  64. regPart = Right(txt_Reg.text, 3) ' Get the last 3 characters of txt_Reg.text **Tested**
  65. BuildWPFull = UCase(regPart & "-" & txt_WPYear.text & "-" & txt_WPNumber.text)
  66. End Function
  67.  
  68. Private Function GetFullName(shortName As String) As String
  69. ' Map short names to full names
  70. Select Case shortName
  71. Case "Dave J"
  72. GetFullName = "David Jones 450901"
  73. Case "Dave M"
  74. GetFullName = "Dave Melanson 414817"
  75. Case "Steve"
  76. GetFullName = "Stephen Humphrey 811691"
  77. Case "Peter"
  78. GetFullName = "Peter Roberts 451738"
  79. Case "Pierre"
  80. GetFullName = "Pierre Damboise 451004"
  81. Case "Marc"
  82. GetFullName = "Marc Vautour 414479"
  83. Case "Ken"
  84. GetFullName = "Ken Branch 415274"
  85. Case Else
  86. GetFullName = shortName ' Return original if no mapping exists
  87. End Select
  88. End Function
  89.  
  90.  
  91.  
  92. Private Sub SetVisibility(ByVal inspectionTypeVisible As Boolean, _
  93. ByVal snagEntryVisible As Boolean, _
  94. ByVal extensionVisible As Boolean)
  95. cmb_InspectionType.Visible = inspectionTypeVisible
  96. label_InspectionType.Visible = inspectionTypeVisible
  97. cb_Extension.Visible = extensionVisible
  98. txt_SnagEntry.Visible = snagEntryVisible
  99. label_SnagEntry.Visible = snagEntryVisible
  100. label_SnagRectification.Visible = snagEntryVisible
  101. txt_SnagRect.Visible = snagEntryVisible
  102. End Sub
  103.  
  104. Private Sub opt_Snag_Click()
  105.  
  106. SetVisibility False, True, False
  107. UpdateContentBoxesVisibility
  108. End Sub
  109.  
  110. Private Sub opt_Maint_Click()
  111. SetVisibility True, False, True
  112. UpdateContentBoxesVisibility
  113. End Sub
  114.  
  115. Private Sub opt_Both_Click()
  116. SetVisibility True, True, True
  117. UpdateContentBoxesVisibility
  118. End Sub
  119. Private Sub UpdateContentBoxesVisibility()
  120. Dim ccSnag As ContentControl
  121. Dim ccMaint As ContentControl
  122.  
  123. ' Get reference to content controls
  124. Set ccSnag = ActiveDocument.SelectContentControlsByTag("box_Snag")(1)
  125. Set ccMaint = ActiveDocument.SelectContentControlsByTag("box_Maint")(1)
  126.  
  127. ' Set visibility based on the selected option button
  128. If opt_Snag.Value Then
  129. ccSnag.Range.Font.Hidden = False
  130. ccMaint.Range.Font.Hidden = True
  131. ElseIf opt_Maint.Value Then
  132. ccSnag.Range.Font.Hidden = True
  133. ccMaint.Range.Font.Hidden = False
  134. ElseIf opt_Both.Value Then
  135. ccSnag.Range.Font.Hidden = False
  136. ccMaint.Range.Font.Hidden = False
  137. End If
  138. End Sub
  139.  
  140.  
  141. Private Sub btnSubmit_Click()
  142.  
  143. 'Make WPFull string available
  144. Dim doc As Document
  145. Dim WPFull As String
  146. WPFull = BuildWPFull()
  147.  
  148.  
  149. ' Set the active document
  150. Set doc = Application.ActiveDocument
  151.  
  152. ' After handling the button click, update the content controls **Tested
  153. Call UpdateContentControls
  154.  
  155. ' If Snag or Both is checked, enter Snag Entry and Rectification **Tested
  156. If opt_Snag.Value = True Or opt_Both.Value = True Then
  157. ' Prepend "Snag: " to the text and call the module procedure
  158. UpdateSnagContent "Snag: " & txt_SnagEntry.Value, "text_SnagTitle"
  159. UpdateSnagContent txt_SnagRect.Value, "text_SnagRectify"
  160.  
  161. End If
  162.  
  163.  
  164. ' Updates inspection type with or without extension in Maintenance header **Tested
  165. UpdateMaintHeader doc, cmb_InspectionType.Value, cb_Extension.Value
  166.  
  167. ' Adds extension entry and hours
  168. Dim ExtensionChecked As Boolean
  169. Dim AddWorkChecked As Boolean
  170. Dim inspectionType As String
  171.  
  172. ' Capture values from the userform for extension
  173. ExtensionChecked = cb_Extension.Value
  174. AddWorkChecked = cb_Addwork.Value
  175. inspectionType = cmb_InspectionType.Value
  176.  
  177. ' Call the UpdateMaintenanceBody subroutine
  178. UpdateMaintenanceBody ExtensionChecked, inspectionType, AddWorkChecked
  179.  
  180.  
  181.  
  182. ' Updates compass headings, only if compass checkmark is ticked
  183. If cb_Compass.Value = True Then
  184. ' Call the UpdateCompassHeadings subroutine to update the compass headings in the document
  185. UpdateCompassHeadings
  186. End If
  187.  
  188.  
  189. ' Add bottom entries with user-specific data
  190. Call AddBottomEntries(text25.Value, text5.Value, txtCustomEntry.Value)
  191.  
  192. End Sub
  193.  
  194.  
  195. Private Sub UpdateContentControls()
  196. Dim cc As ContentControl
  197. Dim WPFull As String
  198. ' Build the WPFull string
  199. WPFull = BuildWPFull()
  200.  
  201. ' Loop through all content controls in the document
  202. For Each cc In ActiveDocument.ContentControls
  203. Select Case cc.tag
  204. Case "Text_Reg"
  205. cc.Range.text = UCase(txt_Reg.text) ' Convert to uppercase before setting the value
  206. Case "Text_Date"
  207. cc.Range.text = txt_Date.text
  208. Case "Doc_RecDef"
  209. cc.Range.text = cmb_RecurDef.Value
  210. Case "Text_TTAF"
  211. cc.Range.text = txt_TTAF.text & " Hrs"
  212. Case "Text_WPFull"
  213. cc.Range.text = WPFull ' Update the WPFull content control
  214. cc.Range.Font.Bold = True ' Apply bold formatting
  215. Case "Doc_InspectionType"
  216. cc.Range.text = cmb_InspectionType.Value
  217. End Select
  218. Next cc
  219. End Sub
  220. Private Sub cb_Compass_Click()
  221. Dim doc As Document
  222. Dim cc As ContentControl
  223. Dim tbl As Table
  224. Dim ccInTable As ContentControl
  225. Dim tblRange As Range
  226.  
  227. ' Check the state of the checkbox and hide/show CompassFrame accordingly
  228. CompassFrame.Visible = cb_Compass.Value
  229.  
  230. ' Reference the active document
  231. Set doc = ActiveDocument
  232.  
  233. ' Find the table content control by its title or tag
  234. For Each cc In doc.ContentControls
  235. If cc.Title = "box_Compass" Or cc.tag = "box_Compass" Then
  236. If cc.Range.Tables.Count > 0 Then
  237. Set tbl = cc.Range.Tables(1) ' Get the table within the content control
  238. Set tblRange = tbl.Range
  239. Exit For
  240. End If
  241. End If
  242. Next cc
  243.  
  244. ' If the table is found, toggle its visibility based on the checkbox value
  245. If Not tbl Is Nothing Then
  246. If cb_Compass.Value Then
  247. tblRange.Font.Hidden = False ' Show the table
  248. ' Show all content controls within the table
  249. For Each ccInTable In doc.ContentControls
  250. If ccInTable.Range.Start >= tblRange.Start And ccInTable.Range.End <= tblRange.End Then
  251. ccInTable.Range.Font.Hidden = False
  252. End If
  253. Next ccInTable
  254. Else
  255. tblRange.Font.Hidden = True ' Hide the table
  256. ' Hide all content controls within the table
  257. For Each ccInTable In doc.ContentControls
  258. If ccInTable.Range.Start >= tblRange.Start And ccInTable.Range.End <= tblRange.End Then
  259. ccInTable.Range.Font.Hidden = True
  260. End If
  261. Next ccInTable
  262. End If
  263. End If
  264. End Sub
  265.  
  266. Private Sub UpdateCompassHeadings()
  267. Dim cc As ContentControl
  268. Dim userFormControl As MSForms.Control
  269. Dim contentControlName As String
  270. Dim userFormTextboxName As String
  271.  
  272. ' Loop through all content controls in the document
  273. For Each cc In ActiveDocument.ContentControls
  274. ' Check if the content control's tag matches one of the predefined values
  275. Select Case cc.tag
  276. Case "text_North", "text_30", "text_60", "text_East", "text_120", _
  277. "text_150", "text_South", "text_210", "text_240", _
  278. "text_West", "text_300", "text_330"
  279.  
  280. ' Determine the corresponding textbox on the userform based on the tag
  281. userFormTextboxName = Replace(cc.tag, "text_", "txt")
  282.  
  283. ' Check if the textbox exists on the userform
  284. On Error Resume Next
  285. Set userFormControl = Me.Controls(userFormTextboxName)
  286. On Error GoTo 0
  287.  
  288. ' If the textbox exists, update the content control with its value
  289. If Not userFormControl Is Nothing Then
  290. cc.Range.text = UCase(userFormControl.Value) ' Convert to uppercase
  291. End If
  292. End Select
  293. Next cc
  294. End Sub
  295.  
  296.  
  297. Private Sub cb_Extension_Click()
  298. label_ExtendTime.Visible = cb_Extension.Value
  299. txt_Extension.Visible = cb_Extension.Value
  300. End Sub
  301.  
  302. Private Sub cb_FireExt_Click()
  303. FireExtFrame.Visible = cb_FireExt.Value
  304. End Sub
  305.  
  306. Private Sub cb_FirstAidKit_Click()
  307. FirstAidFrame.Visible = cb_FirstAidKit.Value
  308. End Sub
  309.  
  310. Private Sub cb_WB_Click()
  311. WBFrame.Visible = cb_WB.Value
  312. End Sub
  313.  
  314.  
  315. Private Sub AddBottomEntries(userNumberX As String, userNumberY As String, customEntry As String)
  316. Dim i As Integer
  317. Dim selectedItem As String
  318.  
  319. For i = 0 To BottomAddsList.ListCount - 1
  320. If BottomAddsList.Selected(i) Then
  321. selectedItem = Replace(Replace(BottomAddsList.List(i), "X", userNumberX), "Y", userNumberY)
  322. AddTextToDocument "*** " & Trim(selectedItem) & " ***", True
  323. End If
  324. Next i
  325.  
  326. ' If there is a custom entry, add it to the document
  327. If customEntry <> "" Then
  328. AddTextToDocument "*** " & Trim(customEntry) & " ***", True
  329. End If
  330. End Sub
  331.  
  332. Private Sub AddTextToDocument(text As String, alignCenter As Boolean)
  333. Selection.EndKey Unit:=wdStory
  334. Selection.TypeParagraph
  335. If alignCenter Then
  336. Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
  337. End If
  338. Selection.TypeText text:=text & vbCrLf
  339. End Sub
  340.  
  341. Private Sub cb_Duals_Click()
  342. ' Get reference to the document
  343. Dim doc As Document
  344. Set doc = ActiveDocument
  345.  
  346. DualsFrame.Visible = cb_Duals.Value
  347.  
  348. ' Get reference to the content control box
  349. Dim boxDuals As ContentControl
  350. On Error Resume Next
  351. Set boxDuals = doc.SelectContentControlsByTitle("box_Duals").item(1)
  352. On Error GoTo 0
  353.  
  354. ' Check if the content control exists
  355. If boxDuals Is Nothing Then
  356. MsgBox "Content control 'box_Duals' not found!", vbExclamation
  357. Exit Sub
  358. End If
  359.  
  360. ' Show/hide the box based on checkbox state
  361. If cb_Duals.Value Then
  362. boxDuals.Range.Font.Hidden = False
  363. Else
  364. boxDuals.Range.Font.Hidden = True
  365. End If
  366. End Sub
  367.  
  368. Private Sub cb_DualTCs_Click()
  369. On Error GoTo ErrorHandler
  370. 'Shows Duals userform
  371. DualsUserform.Show
  372. Exit Sub
  373.  
  374. ErrorHandler:
  375. HandleError "cb_DualTCs_Click", Err.Number, GetErrorDescription(Err.Number)
  376. End Sub
  377.  
  378. Private Sub cmb_Duals_Change()
  379. On Error GoTo ErrorHandler
  380.  
  381. ' When a name is selected, get its full version
  382. Dim fullName As String
  383. Dim cc As ContentControl
  384.  
  385. fullName = GetFullName(cmb_Duals.Value)
  386.  
  387. ' Using tag property to identify the content control
  388. For Each cc In ActiveDocument.ContentControls
  389. If cc.tag = "text_PerfDual" Then
  390. cc.Range.text = fullName
  391. Exit For
  392. End If
  393. Next cc
  394.  
  395. Exit Sub
  396.  
  397. ErrorHandler:
  398. HandleError "cmb_Duals_Change", Err.Number, GetErrorDescription(Err.Number)
  399. End Sub
  400.  
  401. 'Duals userform
  402. Option Explicit
  403. Private counter As Integer
  404.  
  405. Private Sub UserForm_Initialize()
  406. counter = 1
  407. End Sub
  408.  
  409. Private Sub cb_AddRow_Click()
  410. ' Increment counter for new textbox naming
  411. counter = counter + 1
  412.  
  413. ' Get reference to last textboxes for positioning
  414. Dim lastControlBox As MSForms.TextBox
  415. Dim lastTCBox As MSForms.TextBox
  416. Set lastControlBox = Me.Controls("txt_DualControl" & (counter - 1))
  417. Set lastTCBox = Me.Controls("txt_DualTC" & (counter - 1))
  418.  
  419. ' Create new textboxes
  420. Dim newControlBox As MSForms.TextBox
  421. Dim newTCBox As MSForms.TextBox
  422.  
  423. ' Create and set properties for Control description textbox
  424. Set newControlBox = Me.Controls.Add("Forms.TextBox.1", "txt_DualControl" & counter)
  425. With newControlBox
  426. .Left = lastControlBox.Left
  427. .Top = lastControlBox.Top + lastControlBox.Height + 5
  428. .Width = lastControlBox.Width
  429. .Height = lastControlBox.Height
  430. End With
  431.  
  432. ' Create and set properties for Task Card textbox
  433. Set newTCBox = Me.Controls.Add("Forms.TextBox.1", "txt_DualTC" & counter)
  434. With newTCBox
  435. .Left = lastTCBox.Left
  436. .Top = lastTCBox.Top + lastTCBox.Height + 5
  437. .Width = lastTCBox.Width
  438. .Height = lastTCBox.Height
  439. End With
  440.  
  441. ' Add new row to the table in the document
  442. Dim cc As ContentControl
  443. Dim tbl As Table
  444.  
  445. ' Find the content control by its tag
  446. For Each cc In ActiveDocument.ContentControls
  447. If cc.tag = "box_DualTCs" Then
  448. Set tbl = cc.Range.Tables(1)
  449. ' Add new row to the table
  450. tbl.Rows.Add
  451. Exit For
  452. End If
  453. Next cc
  454. End Sub
  455.  
  456. Public Sub TransferDataToTable()
  457. Dim cc As ContentControl
  458. Dim tbl As Table
  459. Dim i As Integer
  460.  
  461. ' Find the content control and its table
  462. For Each cc In ActiveDocument.ContentControls
  463. If cc.tag = "box_DualTCs" Then
  464. Set tbl = cc.Range.Tables(1)
  465.  
  466. ' Loop through all textbox pairs and add their data to the table
  467. For i = 1 To counter
  468. Dim controlBox As MSForms.TextBox
  469. Dim tcBox As MSForms.TextBox
  470.  
  471. Set controlBox = Me.Controls("txt_DualControl" & i)
  472. Set tcBox = Me.Controls("txt_DualTC" & i)
  473.  
  474. ' Add data to table
  475. tbl.Rows(i).Cells(1).Range.text = controlBox.text
  476. tbl.Rows(i).Cells(2).Range.text = tcBox.text
  477. Next i
  478.  
  479. Exit For
  480. End If
  481. Next cc
  482. End Sub
  483.  
  484.  
  485. Private Sub cb_AddData_Click()
  486.  
  487. 'Submits the data into the document
  488. TransferDataToTable
  489.  
  490. 'HIDES the Duals form
  491. Me.Hide
  492.  
  493. End Sub
  494.  
  495.  
  496.  
  497. 'Formatting Module
  498. Public Sub ApplyTextFormatToText(ByRef targetRange As Range, _
  499. ByVal textToFormat As String, _
  500. Optional ByVal FontName As String = "Times New Roman", _
  501. Optional ByVal FontSize As Single = 8, _
  502. Optional ByVal Bold As Boolean = True, _
  503. Optional ByVal Italic As Boolean = False, _
  504. Optional ByVal Underline As Boolean = False, _
  505. Optional ByVal FontColor As Long = wdColorAutomatic, _
  506. Optional ByVal Alignment As WdParagraphAlignment = wdAlignParagraphLeft)
  507. ' Check if targetRange is valid
  508. If targetRange Is Nothing Or targetRange.text = "" Then Exit Sub
  509.  
  510. ' Find and format the text
  511. With targetRange.Find
  512. .text = textToFormat
  513. .MatchCase = False
  514. .MatchWholeWord = False
  515. If .Execute Then
  516. With .Parent
  517. ' Apply font properties
  518. With .Font
  519. .Name = FontName
  520. .Size = FontSize
  521. .Bold = Bold
  522. .Italic = Italic
  523. .Underline = IIf(Underline, wdUnderlineSingle, wdUnderlineNone)
  524. .Color = FontColor
  525. End With
  526. ' Apply paragraph alignment
  527. .ParagraphFormat.Alignment = Alignment
  528. End With
  529. End If
  530. End With
  531. End Sub
  532.  
  533.  
  534. ' Helper function to add section content with proper formatting
  535. Public Sub AddFormattedSection(ByRef content As String, ByVal mainText As String, ByRef subItems() As String, ByVal WPFull As String)
  536. content = content & vbCrLf & mainText & " REF WP " & WPFull
  537. Dim subItem As Variant
  538. For Each subItem In subItems
  539. If subItem <> "" Then
  540. content = content & vbCrLf & subItem
  541. End If
  542. Next subItem
  543. End Sub
  544.  
  545.  
  546. 'Updating module
  547.  
  548. Public Sub UpdateSnagContent(ByVal textToInsert As String, ByVal contentTag As String)
  549. Dim doc As Document
  550. Dim cc As ContentControl
  551.  
  552. ' Get the active document
  553. Set doc = ActiveDocument
  554.  
  555. ' Update content if conditions are met (for SnagRect)
  556. If contentTag = "text_SnagRectify" Then
  557. If Not (ReleaseHub.opt_Snag.Value = True Or ReleaseHub.opt_Both.Value = True) Then
  558. Exit Sub
  559. End If
  560. End If
  561.  
  562. ' Find and update the content control
  563. For Each cc In doc.ContentControls
  564. If cc.tag = contentTag Then
  565. cc.Range.text = textToInsert
  566. Exit For
  567. End If
  568. Next cc
  569. End Sub
  570.  
  571.  
  572.  
  573. Public Sub UpdateMaintHeader(doc As Word.Document, inspectionType As String, isExtension As Boolean)
  574. Dim cc As Word.ContentControl
  575. Dim maintTitleText As String
  576.  
  577. 'Sub is good, only updates header.
  578.  
  579. ' Find the content control by tag
  580. For Each cc In doc.ContentControls
  581. If cc.tag = "text_MaintTitle" Then Exit For
  582. Next cc
  583.  
  584. If cc Is Nothing Then Exit Sub ' Exit silently if not found
  585.  
  586. ' Determine the text to set based on isExtension value
  587. If isExtension Then
  588. maintTitleText = "Maintenance: " & inspectionType & " extension to be carried out"
  589. Else
  590. maintTitleText = "Maintenance: " & inspectionType & " to be carried out"
  591. End If
  592.  
  593. ' Update the content control text
  594. cc.Range.text = maintTitleText
  595. End Sub
  596.  
  597.  
  598. ' Helper function to format each paragraph with proper indentation and styling
  599. Private Sub FormatParagraph(ByVal para As Paragraph, ByVal isMainEntry As Boolean, ByVal isBold As Boolean)
  600. With para.Range
  601. .Font.Size = 8
  602. .Font.Bold = isBold
  603. .ListFormat.ListLevelNumber = IIf(isMainEntry, 1, 2)
  604. End With
  605. End Sub
  606.  
  607. ' Function to handle Fire Extinguisher section
  608. Private Function GetFireExtinguisherContent(ByVal frm As ReleaseHub, ByVal WPFull As String) As String
  609. If Not frm.cb_FireExt.Value Then Exit Function
  610.  
  611. Dim content As String
  612. Dim subItems(2) As String
  613. subItems(0) = "Next annual inspection due " & frm.txt_FireAnnual.Value
  614. subItems(1) = "Next 6 year inspection due " & frm.txt_Fire6Year.Value
  615. subItems(2) = "Next 12 year hydrostatic inspection due " & frm.txt_Fire12Year.Value
  616.  
  617. AddFormattedSection content, "Fire extinguisher annual inspection carried out", subItems, WPFull
  618. GetFireExtinguisherContent = content
  619. End Function
  620.  
  621. ' Function to handle First Aid Kit section
  622. Private Function GetFirstAidKitContent(ByVal frm As ReleaseHub, ByVal WPFull As String) As String
  623. If Not frm.cb_FirstAidKit.Value Then Exit Function
  624.  
  625. Dim content As String
  626. Dim subItems(0) As String
  627. subItems(0) = "Next annual inspection due " & frm.txt_FirstAidAnnual.Value
  628.  
  629. AddFormattedSection content, "First aid kit annual inspection carried out", subItems, WPFull
  630. GetFirstAidKitContent = content
  631. End Function
  632.  
  633. ' Function to handle Weight and Balance section
  634. Private Function GetWeightBalanceContent(ByVal frm As ReleaseHub, ByVal WPFull As String) As String
  635. If Not frm.cb_WB.Value Then Exit Function
  636.  
  637. Dim content As String
  638. Dim subItems(2) As String
  639. subItems(0) = "New aircraft empty weight: " & frm.txt_WBEW.Value & " Lbs"
  640. subItems(1) = "New aircraft C of G arm: " & frm.txt_WBCoG.Value & " inches"
  641. subItems(2) = "New aircraft moment: " & frm.txt_WBMoment.Value
  642.  
  643. AddFormattedSection content, "Weight and balance amendment # " & frm.txt_WBAmend.Value & " now in effect.", subItems, WPFull
  644. GetWeightBalanceContent = content
  645. End Function
  646.  
  647. ' Main procedure
  648. Public Sub UpdateMaintenanceBody(ByVal ExtensionValue As Boolean, ByVal InspectionTypeValue As String, ByVal AddWorkChecked As Boolean)
  649. Dim doc As Document
  650. Set doc = ActiveDocument
  651.  
  652. Dim frm As ReleaseHub
  653. Set frm = ReleaseHub
  654.  
  655. Dim WPFull As String
  656. WPFull = frm.BuildWPFull
  657.  
  658. ' Get the content control
  659. Dim ccRange As Range
  660. Set ccRange = doc.SelectContentControlsByTag("text_MaintBody")(1).Range
  661.  
  662. ' Build the initial content
  663. Dim content As String
  664. If ExtensionValue Then
  665. content = InspectionTypeValue & " and all related tasks in WP " & WPFull & _
  666. " extended 10 hours and now due at " & frm.txt_Extension.Value & " Hrs"
  667. Else
  668. content = InspectionTypeValue & " carried out REF WP " & WPFull
  669. End If
  670.  
  671. ' Add additional work line if checked
  672. If AddWorkChecked Then
  673. content = content & vbCrLf & "Additional work carried out REF WP " & WPFull
  674. End If
  675.  
  676. ' Add specialized sections
  677. content = content & GetFireExtinguisherContent(frm, WPFull)
  678. content = content & GetFirstAidKitContent(frm, WPFull)
  679. content = content & GetWeightBalanceContent(frm, WPFull)
  680.  
  681. ' Add compass swing if checked
  682. If frm.cb_Compass.Value Then
  683. content = content & vbCrLf & "Compass swing carried out REF WP " & WPFull & ". New headings below."
  684. End If
  685.  
  686. ' Set the content
  687. ccRange.text = content
  688.  
  689. ' Format the content
  690. With ccRange
  691. .Font.Size = 8
  692. .ListFormat.RemoveNumbers
  693. .ListFormat.ApplyListTemplateWithLevel _
  694. ListTemplate:=ListGalleries(wdNumberGallery).ListTemplates(1), _
  695. ContinuePreviousList:=False, _
  696. ApplyTo:=wdListApplyToWholeList, _
  697. DefaultListBehavior:=wdWord10ListBehavior
  698.  
  699. ' Format each paragraph
  700. For Each mainPara In .Paragraphs
  701. Dim isMainEntry As Boolean
  702. Dim isBold As Boolean
  703.  
  704. ' Determine formatting based on content
  705. If InStr(mainPara.Range.text, "Weight and balance") > 0 Then
  706. isMainEntry = True
  707. isBold = True
  708. ElseIf InStr(mainPara.Range.text, "New aircraft") > 0 Then
  709. isMainEntry = False
  710. isBold = True
  711. ElseIf InStr(mainPara.Range.text, "Next") > 0 Then
  712. isMainEntry = False
  713. isBold = False
  714. Else
  715. isMainEntry = True
  716. isBold = False
  717. End If
  718.  
  719. FormatParagraph mainPara, isMainEntry, isBold
  720. Next mainPara
  721. End With
  722. End Sub
  723.  
  724.  
Advertisement
Add Comment
Please, Sign In to add comment