I'm now trying to tidy up my existing forms to utilise gmayor's submacro for Bookmarks, but I have an variable error popping up when either Button1 or Button2 are selected on the UserForm. The idea is for the user to only be able to select Button1 or Button2.
I've been staring at the code for so long now I just cannot see what is wrong!
Option Explicit 'Cancel button Private Sub CancelBut_Click() Unload Me End Sub Private Sub EnterBut_Click() Dim onumber As Range, oName As Range Dim oAddress As Range, oAggrieved As Range, oCommunication As Range Dim oMethod As Range, oReason As Range, oReviewer As Range 'Check required fields are filled out If TextBox1.Text = "44200" Then MsgBox "Enter full number", vbCritical, "Triage Hub" TextBox1.SetFocus Exit Sub End If If TextBox2.Text = "" Then MsgBox "Provide full Name", vbCritical, "Triage Hub" TextBox2.SetFocus Exit Sub End If If TextBox3.Text = "" Then MsgBox "Provide full Address", vbCritical, "Triage Hub" TextBox3.SetFocus Exit Sub End If If TextBox4.Text = "" Then MsgBox "Provide Checker's Name", vbCritical, "Triage Hub" TextBox4.SetFocus Exit Sub End If If ComboBox1.ListIndex = 0 Then MsgBox "Provide Communication Method", vbCritical, "Triage Hub" ComboBox1.SetFocus Exit Sub End If If ComboBox2.ListIndex = 0 Then MsgBox "State either Enclosed or Attached", vbCritical, "Triage Hub" ComboBox2.SetFocus Exit Sub End If If TextBox5.Text = "" Then MsgBox "Enter Reviewer's Details", vbCritical, "Triage Hub" TextBox5.SetFocus Exit Sub End If 'use FillBM function to write to bookmarks FillBM "number", TextBox1.Text FillBM "Name", TextBox2.Text 'FillBM "Name1", TextBox2.Text FillBM "Address", TextBox3.Text FillBM "Communication", ComboBox1.Value FillBM "Method", ComboBox2.Value 'FillBM "Reason", ComboBox3.Value FillBM "Reviewer", TextBox5.Text Set onumber = Nothing Set oName = Nothing 'Set oName1 = Nothing Set oAddress = Nothing Set oCommunication = Nothing Set oMethod = Nothing 'Set oReason = Nothing Set oReviewer = Nothing Unload Me lbl_Exit: 'Provide prompt to record that review has taken place MsgBox "Remember to update the stats to indicate Cyber Crime!", vbExclamation, "Triage Hub" Exit Sub End Sub 'Only one of these should be selected Private Sub Button1_Click() If Me.Button1.Value = True Then Set oRng = ActiveDocument.Bookmarks("Reason").Range oRng.Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." ActiveDocument.Bookmarks.Add "Reason", oRng End If End Sub Private Sub Button2_Click() If Me.Button2.Value = True Then Set oRng = ActiveDocument.Bookmarks("Reason").Range oRng.Text = "Proin sed nisl enim. Cras in nisl tempus, scelerisque mi id, vulputate arcu." ActiveDocument.Bookmarks.Add "Reason", oRng End If End Sub Private Sub UserForm_Initialize() Dim myArray() As String 'Use Split function to return a zero based one dimensional array myArray = Split("- Select Method of Offence -|by text|by social media|by email|" _ & "by letter|by phone", "|") 'Use List method to populate listbox ComboBox1.List = myArray ComboBox1.ListIndex = 0 'Redefine list 'Use Split function to return a zero based one dimensional array myArray = Split("- Select -|enclosed|attached", "|") 'Use List method to populate listbox ComboBox2.List = myArray ComboBox2.ListIndex = 0 lbl_Exit: Exit Sub End Sub Private Sub FillBM(strbmName As String, strValue As String) 'Graham Mayor - http://www.gmayor.com Dim oRng As Range With ActiveDocument On Error GoTo lbl_Exit If .Bookmarks.Exists(strbmName) = True Then Set oRng = .Bookmarks(strbmName).Range oRng.Text = strValue oRng.Font.Color = lngColor oRng.Bookmarks.Add strbmName End If End With lbl_Exit: Set oRng = Nothing Exit Sub End Sub






Reply With Quote