Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA - How do I set an object variable?

Status
Not open for further replies.

Gwynne

MIS
Sep 20, 1999
19
0
0
US
Hello All,

I am a nu-B and don’t know much about programming. I have been tasked with converting WP 5.1 macros to Word XP and boy, do I need help!

I have created a template, and am using InputBoxes to gather information to be plugged into the document. At one point the user will have to make a decision as to whether a document was recorded in a Volume/Page or a Transaction. I have created a UserForm with 2 radio buttons allowing the user to choose one or the other. I need the UserForm to appear at the right time, but keep getting an error 91 “Object variable or With block variable not set.” My question is: How do I set an object variable?

Here is my code so far:

Private Sub Document_New()

'declare vars
Dim strCaseNum, strDefName, strCrimCrt As String
Dim strVolume, strPage, strTransNum As String
Dim frmVolumePageOrTransaction As UserForm
Dim optVolumePage As OptionButton

'set name vars to input
strCaseNum = InputBox("Enter the Case Number.")
strDefName = InputBox("Enter the Defendant's Name.")
strCrimCrt = InputBox("Enter the Numbered Court.")
frmVolumePageOrTransaction.Show
If optVolumePage = True Then
strVolume = InputBox("Enter The Volume Number.")
strPage = InputBox("Enter The Page Number.")
Else
strTransNum = InputBox("Enter the Transaction Number")
End IfstrVolume = InputBox("Enter The Volume Number.")
strPage = InputBox("Enter The Page Number.")
strTransNum = InputBox("Enter the Transaction Number")

'set field results to name vars
ActiveDocument.FormFields("Text1").Result = strCaseNum
ActiveDocument.FormFields("Text2").Result = strDefName
ActiveDocument.FormFields("Text3").Result = strCrimCrt
ActiveDocument.FormFields("Text7").Result = strVolume
ActiveDocument.FormFields("Text8").Result = strPage
ActiveDocument.FormFields("Text9").Result = strTransNum

End Sub

Any help would be appreciated before I become bald!!

Gwynne
 
Gwynne: You did change the name in the form properties to "frmVolumePageOrTransactio" when you changed the macro, didn't you?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top