mrsjetset
06-30-2016, 07:35 AM
First off, I am completely new to VBA and am struggling through. I have a few questions and have tried a couple of other forums and just got tired of everyone treating me like I was stupid because I had basic questions. So, here I am.
I have created a simple multi-page userform to fill in the blanks on a basic will. (I didn't use a plain MS Word form as sometimes my client will need to make edits to the text of the will, so that wouldn't work as best I could tell.)
Here is where I'm at now. I have the form and quite a bit of coding complete, but have encountered a few issues:
1-Some of the bookmarks also have cross-references that refer back to them, and while I have finally grasped the concept of the subroutine and running it multiple times, my cross-references end up formatted like the original bookmark rather than like the text surrounding them. (I.E. my first bookmark is the person's name. At the original bookmark location, the font size is larger than the rest of the document, so in all the cross-references, the person's name is two sizes larger than all the surrounding text.) I feel like in my never ending research on VBA and userforms that I found a solution to this issue, but I can't seem to find it again.
2-In the code for my cmdOK_Click subroutine, my last line is Unload Me, but the form doesn't disappear. I can click OK and then the X, and it will close, but that's it. Do I need a separate Close button? I was under the impression the Unload Me should work, but it is totally possible I have misunderstood.
3-When I open a new document from the template, it opens the form on whichever page I edited last, rather than the first page. Is there a way to make page 1 the default? I didn't see anything in properties, but honestly a lot of the things there I have no idea what they do.
Here is my code for the userform:
Private Sub UserForm_Initialize()
With cboCountyReside
.AddItem "Barrow"
.AddItem "Bartow"
.AddItem "Carroll"
.AddItem "Cherokee"
.AddItem "Clayton"
.AddItem "Cobb"
.AddItem "Coweta"
.AddItem "Dekalb"
.AddItem "Douglas"
.AddItem "Fayette"
.AddItem "Forsyth"
.AddItem "Fulton"
.AddItem "Gwinnett"
.AddItem "Hall"
.AddItem "Henry"
.AddItem "Jackson"
.AddItem "Newton"
.AddItem "Paulding"
.AddItem "Pickens"
.AddItem "Rockdale"
.AddItem "Spalding"
.AddItem "Walton"
End With
With cboCountyMade
.AddItem "Barrow"
.AddItem "Bartow"
.AddItem "Carroll"
.AddItem "Cherokee"
.AddItem "Clayton"
.AddItem "Cobb"
.AddItem "Coweta"
.AddItem "Dekalb"
.AddItem "Douglas"
.AddItem "Fayette"
.AddItem "Forsyth"
.AddItem "Fulton"
.AddItem "Gwinnett"
.AddItem "Hall"
.AddItem "Henry"
.AddItem "Jackson"
.AddItem "Newton"
.AddItem "Paulding"
.AddItem "Pickens"
.AddItem "Rockdale"
.AddItem "Spalding"
.AddItem "Walton"
End With
End Sub
Private Sub cmdCancel_Click()
Unload Me
ActiveDocument.Close SaveChanges:=False
End Sub
Private Sub cmdClear_Click()
optMaleValue = False
optFemale.Value = False
optExecutor.Value = False
optExecutrix.Value = False
optExecutor2.Value = False
optExecutrix2.Value = False
txtTestatorName.Value = Null
txtDateMade.Value = Null
cboCountyReside.Value = Null
cboCountyMade.Value = Null
txtPrimeBeneficiary.Value = Null
txtPrimeBenAddress.Value = Null
txtPrimeBenPhone.Value = Null
txtSecondBeneficiary.Value = Null
txtSecondBenAddress.Value = Null
txtSecondBenPhone.Value = Null
txtPersonalRepName.Value = Null
txtPersonalRepAddress.Value = Null
txtPersonalRepPhone.Value = Null
txtSecondPersonalRep.Value = Null
txtSecondPersonalRepAddress.Value = Null
txtSecondPersonalRepPhone.Value = Null
txtAIFName.Value = Null
txtAIFAddress.Value = Null
txtAIFPhone.Value = Null
txtRealtyforPOA.Value = Null
End Sub
Private Sub cmdOK_Click()
Dim strTestatorTestatrix As String
If optMale = True Then strTestatorTestatrix = "Testator"
If optFemale = True Then strTestatorTestatrix = "Testatrix"
Dim strHimHer As String
If optMale = True Then strHimHer = "Him"
If optFemale = True Then strHimHer = "Her"
Dim strHisHer As String
If optMale = True Then strHisHer = "His"
If optFemale = True Then strHisHer = "Her"
Dim strPrimeExecutorExecutrix As String
If optExecutor = True Then strPrimeExecutorExecutrix = "Executor"
If optExecutrix = True Then strPrimeExecutorExecutrix = "Executrix"
Dim strSecondExecutorExecutrix As String
If optExecutor2 = True Then strSecondExecutorExecutrix = "Executor"
If optExecutrix2 = True Then strSecondExecutorExecutrix = "Executrix"
UpdateBookmark "TestatorName", txtTestatorName.Value
UpdateBookmark "DateMade", txtDateMade.Value
UpdateBookmark "CountyMade", cboCountyMade.Value
UpdateBookmark "CountyReside", cboCountyReside.Value
UpdateBookmark "TestatorTestatrix", strTestatorTestatrix
UpdateBookmark "HimHer", strHimHer
UpdateBookmark "HisHer", strHisHer
UpdateBookmark "PrimeBeneficiary", txtPrimeBeneficiary.Value
UpdateBookmark "PrimeBenAddress", txtPrimeBenAddress.Value
UpdateBookmark "PrimeBenPhone", txtPrimeBenPhone.Value
UpdateBookmark "SecondBeneficiary", txtSecondBeneficiary.Value
UpdateBookmark "SecondBenAddress", txtSecondBenAddress.Value
UpdateBookmark "SecondBenPhone", txtSecondBenPhone.Value
UpdateBookmark "PersonalRepTitle", strPrimeExecutorExecutrix
UpdateBookmark "PersonalRepName", txtPersonalRepName.Value
UpdateBookmark "PersonalRepAddress", txtPersonalRepAddress.Value
UpdateBookmark "PersonalRepPhone", txtPersonalRepPhone.Value
UpdateBookmark "SecondPersonalRep", txtSecondPersonalRep.Value
UpdateBookmark "SecondPersonalRepAddress", txtSecondPersonalRepAddress.Value
UpdateBookmark "SecondPersonalRepPhone", txtSecondPersonalRepPhone.Value
UpdateBookmark "SecondPersonalRepTitle", strSecondExecutorExecutrix
UpdateBookmark "AIFName", txtAIFName.Value
UpdateBookmark "AIFAddress", txtAIFAddress.Value
UpdateBookmark "AIFPhone", txtAIFPhone.Value
UpdateBookmark "RealtyforPOA", txtRealtyforPOA.Value
ActiveDocument.Fields.Update
Unload Me
End Sub
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub
I have created a simple multi-page userform to fill in the blanks on a basic will. (I didn't use a plain MS Word form as sometimes my client will need to make edits to the text of the will, so that wouldn't work as best I could tell.)
Here is where I'm at now. I have the form and quite a bit of coding complete, but have encountered a few issues:
1-Some of the bookmarks also have cross-references that refer back to them, and while I have finally grasped the concept of the subroutine and running it multiple times, my cross-references end up formatted like the original bookmark rather than like the text surrounding them. (I.E. my first bookmark is the person's name. At the original bookmark location, the font size is larger than the rest of the document, so in all the cross-references, the person's name is two sizes larger than all the surrounding text.) I feel like in my never ending research on VBA and userforms that I found a solution to this issue, but I can't seem to find it again.
2-In the code for my cmdOK_Click subroutine, my last line is Unload Me, but the form doesn't disappear. I can click OK and then the X, and it will close, but that's it. Do I need a separate Close button? I was under the impression the Unload Me should work, but it is totally possible I have misunderstood.
3-When I open a new document from the template, it opens the form on whichever page I edited last, rather than the first page. Is there a way to make page 1 the default? I didn't see anything in properties, but honestly a lot of the things there I have no idea what they do.
Here is my code for the userform:
Private Sub UserForm_Initialize()
With cboCountyReside
.AddItem "Barrow"
.AddItem "Bartow"
.AddItem "Carroll"
.AddItem "Cherokee"
.AddItem "Clayton"
.AddItem "Cobb"
.AddItem "Coweta"
.AddItem "Dekalb"
.AddItem "Douglas"
.AddItem "Fayette"
.AddItem "Forsyth"
.AddItem "Fulton"
.AddItem "Gwinnett"
.AddItem "Hall"
.AddItem "Henry"
.AddItem "Jackson"
.AddItem "Newton"
.AddItem "Paulding"
.AddItem "Pickens"
.AddItem "Rockdale"
.AddItem "Spalding"
.AddItem "Walton"
End With
With cboCountyMade
.AddItem "Barrow"
.AddItem "Bartow"
.AddItem "Carroll"
.AddItem "Cherokee"
.AddItem "Clayton"
.AddItem "Cobb"
.AddItem "Coweta"
.AddItem "Dekalb"
.AddItem "Douglas"
.AddItem "Fayette"
.AddItem "Forsyth"
.AddItem "Fulton"
.AddItem "Gwinnett"
.AddItem "Hall"
.AddItem "Henry"
.AddItem "Jackson"
.AddItem "Newton"
.AddItem "Paulding"
.AddItem "Pickens"
.AddItem "Rockdale"
.AddItem "Spalding"
.AddItem "Walton"
End With
End Sub
Private Sub cmdCancel_Click()
Unload Me
ActiveDocument.Close SaveChanges:=False
End Sub
Private Sub cmdClear_Click()
optMaleValue = False
optFemale.Value = False
optExecutor.Value = False
optExecutrix.Value = False
optExecutor2.Value = False
optExecutrix2.Value = False
txtTestatorName.Value = Null
txtDateMade.Value = Null
cboCountyReside.Value = Null
cboCountyMade.Value = Null
txtPrimeBeneficiary.Value = Null
txtPrimeBenAddress.Value = Null
txtPrimeBenPhone.Value = Null
txtSecondBeneficiary.Value = Null
txtSecondBenAddress.Value = Null
txtSecondBenPhone.Value = Null
txtPersonalRepName.Value = Null
txtPersonalRepAddress.Value = Null
txtPersonalRepPhone.Value = Null
txtSecondPersonalRep.Value = Null
txtSecondPersonalRepAddress.Value = Null
txtSecondPersonalRepPhone.Value = Null
txtAIFName.Value = Null
txtAIFAddress.Value = Null
txtAIFPhone.Value = Null
txtRealtyforPOA.Value = Null
End Sub
Private Sub cmdOK_Click()
Dim strTestatorTestatrix As String
If optMale = True Then strTestatorTestatrix = "Testator"
If optFemale = True Then strTestatorTestatrix = "Testatrix"
Dim strHimHer As String
If optMale = True Then strHimHer = "Him"
If optFemale = True Then strHimHer = "Her"
Dim strHisHer As String
If optMale = True Then strHisHer = "His"
If optFemale = True Then strHisHer = "Her"
Dim strPrimeExecutorExecutrix As String
If optExecutor = True Then strPrimeExecutorExecutrix = "Executor"
If optExecutrix = True Then strPrimeExecutorExecutrix = "Executrix"
Dim strSecondExecutorExecutrix As String
If optExecutor2 = True Then strSecondExecutorExecutrix = "Executor"
If optExecutrix2 = True Then strSecondExecutorExecutrix = "Executrix"
UpdateBookmark "TestatorName", txtTestatorName.Value
UpdateBookmark "DateMade", txtDateMade.Value
UpdateBookmark "CountyMade", cboCountyMade.Value
UpdateBookmark "CountyReside", cboCountyReside.Value
UpdateBookmark "TestatorTestatrix", strTestatorTestatrix
UpdateBookmark "HimHer", strHimHer
UpdateBookmark "HisHer", strHisHer
UpdateBookmark "PrimeBeneficiary", txtPrimeBeneficiary.Value
UpdateBookmark "PrimeBenAddress", txtPrimeBenAddress.Value
UpdateBookmark "PrimeBenPhone", txtPrimeBenPhone.Value
UpdateBookmark "SecondBeneficiary", txtSecondBeneficiary.Value
UpdateBookmark "SecondBenAddress", txtSecondBenAddress.Value
UpdateBookmark "SecondBenPhone", txtSecondBenPhone.Value
UpdateBookmark "PersonalRepTitle", strPrimeExecutorExecutrix
UpdateBookmark "PersonalRepName", txtPersonalRepName.Value
UpdateBookmark "PersonalRepAddress", txtPersonalRepAddress.Value
UpdateBookmark "PersonalRepPhone", txtPersonalRepPhone.Value
UpdateBookmark "SecondPersonalRep", txtSecondPersonalRep.Value
UpdateBookmark "SecondPersonalRepAddress", txtSecondPersonalRepAddress.Value
UpdateBookmark "SecondPersonalRepPhone", txtSecondPersonalRepPhone.Value
UpdateBookmark "SecondPersonalRepTitle", strSecondExecutorExecutrix
UpdateBookmark "AIFName", txtAIFName.Value
UpdateBookmark "AIFAddress", txtAIFAddress.Value
UpdateBookmark "AIFPhone", txtAIFPhone.Value
UpdateBookmark "RealtyforPOA", txtRealtyforPOA.Value
ActiveDocument.Fields.Update
Unload Me
End Sub
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub