Option Explicit Sub Calc() 'coded by dian@mousetrax.com 'purpose: when the button is clicked, this code checks the values and 'provides an answer to the student '************************** 'declare variables Dim strOne As String Dim intOne As Integer Dim strTwo As String Dim intTwo As Integer Dim strStudent As String Dim intStudent As Integer Dim intAnswer As Integer Dim strSolution As String 'set values to input strOne = ActiveDocument.FormFields("bkOne").Result 'validate a number If Not IsNumeric(strOne) Then errMessage 'bail Exit Sub End If 'End If 'set values to input strTwo = ActiveDocument.FormFields("bkTwo").Result 'validate a number If Not IsNumeric(strTwo) Then errMessage 'bail Exit Sub End If 'End If 'set values to input strStudent = ActiveDocument.FormFields("bkStudentAnswer").Result 'validate a number If Not IsNumeric(strStudent) Then errMessage 'bail Exit Sub End If 'End If 'convert strings (text) to numbers (integers) intOne = CInt(strOne) intTwo = CInt(strTwo) intStudent = CInt(strStudent) 'multiply given values intAnswer = intOne * intTwo 'decipher if answer is correct and set answer text value If intAnswer = intStudent Then strSolution = "Yes, you are correct!" ElseIf intAnswer <> intStudent Then strSolution = "Sorry, that is not right. Try again." End If 'put solution text in document RewrapBookmark "bookAnswer", strSolution End Sub Sub ClearPreviousAnswer() 'coded by dian@mousetrax.com 'purpose: gets called when they enter the value field 'to ensure that they don't assume the current number is correct '**************************** 'update solution in document RewrapBookmark "bookAnswer", "" End Sub Sub RewrapBookmark(ByVal vBookmarkToUpdate As String, vTextToUse As String) 'coded by dian@mousetrax.com 'PURPOSE 'after data is dropped into a bookmarked location in dot 'this procedure will REWRAP the bookmark, since the bookmark 'will be lost after the data dump 'without REWRAP...this data could not be located again for edits 'used for bookmarks only, not form fields w/bookmarks '********************** 'when accessing a bookmark, which is not accessible 'when the form is locked, the lock must be toggled ToggleFormLock 'set bookmark range w/var passed Dim bkRange As Range Set bkRange = ActiveDocument.Bookmarks(vBookmarkToUpdate).Range 'vBookmarkToUpdate is the name of the bookmark to use 'vTextToUse is the data dump variable bkRange.Text = vTextToUse ActiveDocument.Bookmarks.Add vBookmarkToUpdate, bkRange 'toggle relock ToggleFormLock End Sub Sub ToggleFormLock() 'added by dian@mousetrax.com 'PURPOSE 'quickly checks dot state and opens/closes as needed 'to enter data. Normally only used with bookmarks 'but also needed to bypass form field size limits '********************** 'if locked, unlock, else lock If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then ActiveDocument.Unprotect ' Password:=STR_DotPassword Else ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True ', Password:=STR_DotPassword End If End Sub Sub errMessage() 'added by dian@mousetrax.com MsgBox "You must first enter numbers in the boxes!" End Sub