Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub cmb_Test_Click()
- End Sub
- Private Sub UserForm_Initialize()
- InitializeForm
- ' Set opt_Maint as the default selected option
- opt_Maint.Value = True
- End Sub
- Private Function BuildWPFull() As String
- Dim regPart As String
- regPart = Right(txt_Reg.text, 3) ' Get the last 3 characters of txt_Reg.text
- BuildWPFull = UCase(regPart & "-" & txt_WPYear.text & "-" & txt_WPNumber.text)
- End Function
- Private Sub opt_Maint_Click()
- Dim ccMaintenance As contentControl
- Dim Doc_Header As contentControl
- Dim line1 As contentControl
- Dim maintEntry As String
- Dim maintDetail As String
- Dim WPFull As String
- ' Build the WPFull string
- WPFull = BuildWPFull()
- ' Set visibility for Maintenance
- With Me
- cmb_InspectionType.Visible = True
- label_InspectionType.Visible = True
- txt_SnagEntry.Visible = False
- label_SnagEntry.Visible = False
- label_SnagRectification.Visible = False
- txt_SnagRect.Visible = False
- cb_Extension.Visible = True
- End With
- ' Determine maintenance detail based on cb_Extension
- If cb_Extension.Value = True Then
- maintDetail = cmb_InspectionType.Value & " extension carried out" & " REF " & WPFull
- Else
- maintDetail = cmb_InspectionType.Value & " carried out"
- End If
- ' Set the document context for Maintenance type
- Set ccMaintenance = ActiveDocument.SelectContentControlsByTag("Doc_MaintType").Item(1)
- If Not ccMaintenance Is Nothing Then
- ccMaintenance.Range.text = "Maintenance"
- Else
- MsgBox "Content control 'Doc_MaintType' not found!", vbExclamation
- End If
- ' Update the Header with Maintenance entry
- Set Doc_Header = ActiveDocument.SelectContentControlsByTag("Doc_Header").Item(1)
- If Not Doc_Header Is Nothing Then
- If cb_Extension.Value = True Then
- Doc_Header.Range.text = Trim(cmb_InspectionType.Value) & " extension to be carried out"
- Else
- Doc_Header.Range.text = Trim(cmb_InspectionType.Value) & " to be carried out"
- End If
- Else
- MsgBox "Content control 'Doc_Header' not found!", vbExclamation
- End If
- ' Update line1 with Maintenance details
- Set line1 = ActiveDocument.SelectContentControlsByTag("Text_Line1").Item(1)
- If Not line1 Is Nothing Then
- line1.Range.text = maintDetail
- Else
- MsgBox "Content control 'Text_Line1' not found!", vbExclamation
- End If
- End Sub
- Private Sub opt_Snag_Click()
- Dim ccMaintenance As contentControl
- Dim snagEntry As String
- Dim snagRect As String
- Dim docHeader As contentControl
- Dim line1 As contentControl
- ' Set visibility for Snag
- With Me
- cmb_InspectionType.Visible = False
- label_InspectionType.Visible = False
- txt_SnagEntry.Visible = True
- label_SnagEntry.Visible = True
- label_SnagRectification.Visible = True
- txt_SnagRect.Visible = True
- cb_Extension.Visible = False
- End With
- ' Retrieve Snag data
- snagEntry = Trim(txt_SnagEntry.Value)
- snagRect = Trim(txt_SnagRect.Value)
- ' Update 'Doc_MaintType' to "Snag"
- On Error Resume Next
- Set ccMaintenance = ActiveDocument.SelectContentControlsByTag("Doc_MaintType").Item(1)
- On Error GoTo 0
- If Not ccMaintenance Is Nothing Then
- ccMaintenance.Range.text = "Snag"
- Else
- MsgBox "Content control 'Doc_MaintType' not found!", vbExclamation
- End If
- ' Update Doc_Header with Snag entry
- On Error Resume Next
- Set docHeader = ActiveDocument.SelectContentControlsByTag("Doc_Header").Item(1)
- On Error GoTo 0
- If Not docHeader Is Nothing Then
- docHeader.Range.text = snagEntry
- Else
- MsgBox "Content control 'Doc_Header' not found!", vbExclamation
- End If
- ' Update line1 with Snag rectification
- On Error Resume Next
- Set line1 = ActiveDocument.SelectContentControlsByTag("Text_Line1").Item(1)
- On Error GoTo 0
- If Not line1 Is Nothing Then
- line1.Range.text = snagRect
- Else
- MsgBox "Content control 'Text_Line1' not found!", vbExclamation
- End If
- End Sub
- Private Sub btnSubmit_Click()
- If opt_Maint.Value Then
- Call opt_Maint_Click
- ElseIf opt_Snag.Value Then
- Call opt_Snag_Click
- End If
- ' After handling the button click, update the content controls
- Call UpdateContentControls
- ' Add bottom entries with user-specific data
- Dim userNumberX As String
- Dim userNumberY As String
- Dim customEntry As String
- ' Get the numbers from the TextBoxes
- userNumberX = text25.Value
- userNumberY = text5.Value
- customEntry = txtCustomEntry.Value
- ' Add entries to the bottom of the document
- Call AddBottomEntries(userNumberX, userNumberY, customEntry)
- End Sub
- Private Sub UpdateContentControls()
- Dim cc As contentControl
- Dim WPFull As String
- ' Build the WPFull string
- WPFull = BuildWPFull()
- ' Loop through all content controls in the document
- For Each cc In ActiveDocument.ContentControls
- Select Case cc.Tag
- Case "Text_Reg"
- cc.Range.text = UCase(txt_Reg.text) ' Convert to uppercase before setting the value
- 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
- Case "Text_WPFull"
- cc.Range.text = WPFull ' Update the WPFull content control
- cc.Range.Font.Bold = True ' Apply bold formatting
- Case "Doc_InspectionType"
- cc.Range.text = cmb_InspectionType.Value
- End Select
- Next cc
- End Sub
- Private Sub InitializeForm()
- ' Populate the BottomAddsList with preset options
- BottomAddsList.AddItem "Engine leak check required after first flight"
- BottomAddsList.AddItem "Aircraft released conditional to satisfactory 1500hr inspection / engine break in test flight "
- BottomAddsList.AddItem "Aircraft released conditional to satisfactory test flight due to fuel system adjustments carried out"
- BottomAddsList.AddItem "Propeller torque check required after first flight and after first 25hrs to not exceed X hrs TTAF"
- BottomAddsList.AddItem "Initial 5hr alternator belt tension check required to not exceed Y hrs "
- BottomAddsList.AddItem "Initial 25hr engine operation inspection required to not exceed X hrs TTAF"
- BottomAddsList.AddItem "25 hour propeller retorque due at X hrs TTAF"
- ' Allow multiple selections
- BottomAddsList.MultiSelect = fmMultiSelectMulti
- ' Populate cmb_InspectionType
- With Me.cmb_InspectionType
- .AddItem "Maintenance"
- .AddItem "Snag"
- End With
- ' Optional: Set a default value
- Me.cmb_InspectionType.Value = "Maintenance"
- ' Populate cmb_InspectionType
- With Me.cmb_InspectionType
- cmb_InspectionType.Clear
- .AddItem "75 Hour inspection"
- .AddItem "150 Hour inspection"
- .AddItem "300 Hour inspection"
- .AddItem "1500 Hour inspection"
- .AddItem "6000 Hour inspection"
- .AddItem "100 Hour inspection"
- .AddItem "500 Hour inspection"
- .AddItem "1000 Hour inspection"
- End With
- ' Optional: Set a default value
- Me.cmb_InspectionType.Value = "300 Hour"
- ' Populate cmb_RecurDef
- With Me.cmb_RecurDef
- .AddItem "No"
- .AddItem "Yes"
- End With
- ' Optional: Set a default value
- Me.cmb_RecurDef.Value = "No"
- 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 there is a custom entry, add it to the document
- If customEntry <> "" Then
- AddTextToDocument "*** " & Trim(customEntry) & " ***", True
- End If
- End Sub
- Private Sub btnCompass_Click()
- AddNumberedLineToDocument "Compass calibration needed"
- End Sub
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement