Hello all,
This is my first post on this forum - albeit I have been using this website as an invaluable resource on obtaining lots of helpful information on building my access database.
I am building a database for work, and I have setup a database with two tables and two forms. There is the main form, entitled "GeneralInfo" which contains address and property identification fields, and then there is a subform entitled "Records_Subform" which contains all of the other various details about the property in question.
For reasons that would take a long time to explain, I have decided to build a report using Microsoft Word, which I have programmed Access to populate the fields by virtue of identifying bookmarks I specified in Word and populating those fields with data from Access. I have setup a button on the subform that you can click to bring up a new word document and it will fill in all the various fields. Works great except there is one problem. The button only works when I am viewing JUST the subform. If I open the main form and click the button in the subform, it gives me a run-time error #2450, "Microsoft Access cannot find the referenced form 'Records_Subform'."
So there lies the first problem: Why doesn't Access recognize the command in the subform when I have the main form open, and what can I do to correct that (see code below).
A second issue I am struggling with is that in addition to the information captured in the subform, I would like for the command button to also populate a few fields in the Word document that are in the main form, GeneralInfo. How do I reference a code to pull information from the main Form (I've tried several references, but they all end up giving me the same run-time error) if the button is only pulling information from the subform right now?
Key note here: I am operating with Access and Word 2010. I only say that because there is a lot of information out there on these topics that I have found for Access/Word 2003 and 2000, so please bear that in mind.
Also another thing is that I am not a programmer by nature, I have limited knowledge on this stuff so please go easy on me. I am learning as much as I can, but I could never quite wrap my head around this stuff.
Private Sub Command195_Click()
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open ("C:\Documents and Settings\****\Desktop\SamplePC.doc")
.ActiveDocument.Bookmarks("ReporterName").Select
.Selection.Text = (CStr(Forms!Records_Subform!Reporting_Party_Name))
.ActiveDocument.Bookmarks("SiteAddress").Select
.Selection.Text = (CStr(Forms!Records_Subform!Street_Address))
.ActiveDocument.Bookmarks("DescriptionofComplaint").Select
.Selection.Text = (CStr(Forms!Records_Subform!Description_Spill))
.ActiveDocument.Bookmarks("SpillRelease").Select
.Selection.Text = (CStr(Forms!Records_Subform!SpillRelease))
.ActiveDocument.Bookmarks("RespStaffMember").Select
.Selection.Text = (CStr(Forms!Records_Subform!Responsible_Staff))
End With
Exit Sub
The area in bold is one example of where the forms information is at...I guess basically I need to know 1) what do I need to change there to make this work in the main form? and 2) what do I need to change to reference a field that is in the main form?
Hope this makes sense, if not I will clarify as much as possible.
Thank you VERY much for reviewing and assisting if possible!
-David
This is my first post on this forum - albeit I have been using this website as an invaluable resource on obtaining lots of helpful information on building my access database.
I am building a database for work, and I have setup a database with two tables and two forms. There is the main form, entitled "GeneralInfo" which contains address and property identification fields, and then there is a subform entitled "Records_Subform" which contains all of the other various details about the property in question.
For reasons that would take a long time to explain, I have decided to build a report using Microsoft Word, which I have programmed Access to populate the fields by virtue of identifying bookmarks I specified in Word and populating those fields with data from Access. I have setup a button on the subform that you can click to bring up a new word document and it will fill in all the various fields. Works great except there is one problem. The button only works when I am viewing JUST the subform. If I open the main form and click the button in the subform, it gives me a run-time error #2450, "Microsoft Access cannot find the referenced form 'Records_Subform'."
So there lies the first problem: Why doesn't Access recognize the command in the subform when I have the main form open, and what can I do to correct that (see code below).
A second issue I am struggling with is that in addition to the information captured in the subform, I would like for the command button to also populate a few fields in the Word document that are in the main form, GeneralInfo. How do I reference a code to pull information from the main Form (I've tried several references, but they all end up giving me the same run-time error) if the button is only pulling information from the subform right now?
Key note here: I am operating with Access and Word 2010. I only say that because there is a lot of information out there on these topics that I have found for Access/Word 2003 and 2000, so please bear that in mind.
Also another thing is that I am not a programmer by nature, I have limited knowledge on this stuff so please go easy on me. I am learning as much as I can, but I could never quite wrap my head around this stuff.
Private Sub Command195_Click()
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open ("C:\Documents and Settings\****\Desktop\SamplePC.doc")
.ActiveDocument.Bookmarks("ReporterName").Select
.Selection.Text = (CStr(Forms!Records_Subform!Reporting_Party_Name))
.ActiveDocument.Bookmarks("SiteAddress").Select
.Selection.Text = (CStr(Forms!Records_Subform!Street_Address))
.ActiveDocument.Bookmarks("DescriptionofComplaint").Select
.Selection.Text = (CStr(Forms!Records_Subform!Description_Spill))
.ActiveDocument.Bookmarks("SpillRelease").Select
.Selection.Text = (CStr(Forms!Records_Subform!SpillRelease))
.ActiveDocument.Bookmarks("RespStaffMember").Select
.Selection.Text = (CStr(Forms!Records_Subform!Responsible_Staff))
End With
Exit Sub
The area in bold is one example of where the forms information is at...I guess basically I need to know 1) what do I need to change there to make this work in the main form? and 2) what do I need to change to reference a field that is in the main form?
Hope this makes sense, if not I will clarify as much as possible.
Thank you VERY much for reviewing and assisting if possible!
-David
Last edited: