Access 2010 - VB 2010 Express - Word 2010

noticetoowner
noticetoowner used Ask the Experts™
on
I need to write an exe program in VB 2010 Express.  I want to use Access to build data tables to export the info entered into Word documents.  I do not want Access or Word visible to user.  VB will use drop down menus (combo box) for table selection from Access and import that data into the Word documents.  I would think this is possible in VB but is it in the Express version?  What books should I start reading?  Should I start with VB Express or Access (I think the "Bible" is the best one out there but not sure and need advise on that).  If you could recommend books or good links to get me on my way that would be awesome.  Thanks so much!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Christopher KileSenior Software Analyst

Commented:
Some of the stuff you want to do depends on the object models of the applications, which will require you to run your application only on systems where Office is installed (I think this is a licensing limitation strictly as you can download the DLLs for the Microsoft.Office.Interop components, but I'm going to assume you have Office available.

You won't need to do Access programming, but you will need to do .NET programming using Access databases.  More properly, these are JET OLEDB databases.  I assume you want a list of tables that are available rather than to look for table names that you expect to be there.  This information should be easy to obtain using the Access object model.

Similarly, we will use the Microsoft.Interop.Word model to create, fill, and save Word documents formatted.

Important information on installing Office so that .NET access is enabled is mentioned here:  Stack Overflow:  can't find Access.Application

Here's some references for getting lists of tables from Access:
http://www.dreamincode.net/code/snippet806.htm
http://aspalliance.com/542

These references use JET OLEDB to get the list of tables from the Access schema rather than using the Access object model.

These articles will get you started with the Word object model:
http://msdn.microsoft.com/en-us/library/aa192495(v=office.11).aspx
http://msdn.microsoft.com/en-us/library/kw65a0we.aspx      <-- specific to Word 2010

Author

Commented:
I built the tables in Access and have all of my datasets and forms in VB.  My current issue is that the interop file is missing from my Windows.  I have tried to install it 3 times from files (msi) others have sent me and it will not install.  I am backing up now so I can reinstall windows 7 and hopefully remedy this issue.

One quick question.  In my VB text boxes, how do I get the text to copy to a bookmark in Word?  If you could give me that code, that would be awesome.  Thanks a bunch and I will get you your points.

Author

Commented:
I am getting so frustrated.  I have everything ready to go but cannot get the interop to work. I have added all of the office object libraries (including word) but if I type the simple code to open word it doesnt even recognize word.application verbage.  I am lost as to what more to do. I literally wiped out my system, reinstalled windows 7 and office 2010.  It is all fresh.  Can someone please help me.....
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Senior Software Analyst
Commented:
Did you add the references to the Office Primary Interop Assembly for Word to your project?  In Visual Studio 2008, you right-click the project, choose Add reference, choose the .NET tab on the following window then page down until you see Microsoft.Interop.Word, then choose the highest version available (this should be Word 2010).  Let me know if that helps, if not then show me your code, please, as well as the error message you are getting.

Author

Commented:
LOL, right before you sent answer I played around with it to see what I could find.  I did it different though but am going to try your way.  I right clicked and went to the windows assembly file and chose the dll file from there.  It is not on my NET menu which is under projects, add reference, then the NET option is there in 2010.  I got it to open a word document though.  So I am going to write a book for real world idiots once I get this complete.  I have one more step then I can finish this project.  Maybe you can help me.  I have my form set with a text box (several actually) and will need to take that text to a bookmark in the Word document.  Do you happen to have the code for that or direct me to it? That is my last step then I can build the project. THANKS SOOOO MUCH!!!!!
Christopher KileSenior Software Analyst

Commented:
What do you mean by "take that text to a bookmark"?  Do you mean you want to find a bookmark then insert the text?  This article should help, even though it's old:

http://support.microsoft.com/kb/316384

Truth is, I searched for ".NET Word bookmark" to get this entry, and a bunch of others were available.  I've done this code myself, but not for about five or six years at least (the first time I did it was in 1994, when Word Basic was not even VBA yet) so I don't remember it off the top of my head, but this article seemed to get it right.  If you have trouble with it, let me know.

Author

Commented:
That didnt quite work.  I need to open a work document and lets say "place the text in TextBox1.Text in document C:\Users\Mel\ProjectFolder\Lien1.docx"Bookmark1"  I assume after bookmark there would be a stop and then "Bookmark1" or something but I am not sure.

Author

Commented:
I found this: http://tomorrowssolutionsllc.com/materials/automatingword.html and it is kinda long but very informative with code.
Christopher KileSenior Software Analyst

Commented:
Yes, it looks like a friendlier version of some of the other Word model documents I've found, though the reference to Visual Foxpro dates it somewhat.

Author

Commented:
It's different but I think it is something I can start with and learn to navigate around via trial and error, or do you think that will confuse me further and I should look further?
Christopher KileSenior Software Analyst

Commented:
Nope, I think you have the right idea, and you are looking at the right code, so you should be able to work your way through to where you want to go.  Word is fairly tolerant of what you may try since you can always discard the results, just don't use actual production documents until you are ready.
Christopher KileSenior Software Analyst

Commented:
Also, make sure that what you're using can be found in the most recent Word object model (see http://msdn.microsoft.com/en-us/library/kw65a0we.aspx).

Author

Commented:
Here is the code that I have - it has 1 error that I need to fix before running - any ideas?

Error      1      'wdGoToBookmark' is not declared. It may be inaccessible due to its protection level.      C:\Users\Melynda\documents\visual studio 2010\Projects\Lien Protector Florida\Lien Protector Florida\Documents Library.vb      25      40      Lien Protector Florida

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim WordObj As Word.Application
        Dim WordDoc As Word.Document
        Dim WordRange As Word.Range
        WordObj = CreateObject("Word.Application")
        WordDoc = WordObj.Documents.Open _
            ("C:\Users\Melynda\Desktop\Demo.docx")
        WordObj.Visible = True

        ' Go to the bookmark named "testing."
        WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="testing")
        WordRange.InsertAfter("Form1.Project_TextBox.Text")

        WordObj = Nothing
    End Sub

End Class
Christopher KileSenior Software Analyst

Commented:
Yes:

WordRange = WordDoc.GoTo(What:=Word.WdGoToItem.wdGoToBookmark, Name:="testing")

You didn't resolve the reference path to the WdGoToItem value.  Unlike VB 6, where such constants are included globally, .NET requires that the Imports specification includes a path along which an item can be found, or that you include enough path information to resolve it according the imports you are already using.

Author

Commented:
OMG soooo close I can taste it.  Final issue it seems.

How do I refer to the text in my textboxes?  I used Form1.Project_Textbox.Text which of course just entered that data.  Should I be using an = sign in some fashion?  thank you thank you thank you
Christopher KileSenior Software Analyst

Commented:
Since I'm assuming your code is in the form where Project_TextBox is located, how about:

WordRange.InsertAfter(Me.Project_TextBox.Text.ToString)

?

Author

Commented:
OMG I GOT IT

Author

Commented:
Complete code (As I do the drunkin chicken dance to 70s music)

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim WordObj As Word.Application
        Dim WordDoc As Word.Document
        Dim WordRange As Word.Range
        WordObj = CreateObject("Word.Application")
        WordDoc = WordObj.Documents.Open _
            ("C:\Users\Melynda\Desktop\Testing.docx")
        WordObj.Visible = True

        ' Go to the bookmark named "testing."
        WordRange = WordDoc.GoTo(What:=Word.WdGoToItem.wdGoToBookmark, Name:="testing")
        WordRange.InsertAfter(Form1.Project__TextBox.Text)

        WordObj = Nothing
    End Sub

End Class
Christopher KileSenior Software Analyst

Commented:
Congratulations! :D

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial