Visual Studio 2013 Express for Desktop
An Access database with one table
As this project is for proof of concept I'm keeping things very simple until I can get the VB working correctly.
The project consists of one form (Audit.vb) which contains one textbox field ("Report Name"), a button to launch Word and run a template plus a toolbar at the top of the form to move between each record and see its name.
I created an SQL statement using the Query Builder to alphabetically sort the names of each report in the Report Name field. This works OK.
The dataset comprises three records and three columns: ReportName, Title, SubTitle. The Access table is named dbAudit.accdb
The object of the exercise is for the user to navigate through each record whilst observing the name of the report on the form. When they find the record they want they will select the "Launch Word" button. This will launch Word, run the appropriate template and send the contents of the Title and SubTitle fields from the dataset to the resulting document's Custom Document Properties.
Below is the code for the button:
Imports Microsoft.Office.Interop Public Class frmLaunch Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnOpenDoc.Click Dim appWD As Word.Application Dim oDoc As Word.Document Dim oField As String MsgBox("Word will now create the audit document") Err.Clear() On Error GoTo notloaded appWD = GetObject(, "Word.Application") notloaded: If Err.Number = 429 Then appWD = CreateObject("Word.Application") End If appWD.Visible = True appWD.Activate() oDoc = appWD.Documents.Add(Template:="D:\Word 2010 Templates\Audit Report.dotm", NewTemplate:=False) appWD.ActiveDocument.CustomDocumentProperties("Cover Page Title") = "***This is a sample document title***" End Sub End Class
I've cleaned up the code as there have been many lines of failed attempts on my part to write an SQL statement which can put the result into a variable and which, in turn, can replace the hard coded reference I've made to a sample document title. Everything above works OK as coded so far.
It's just the part dealing with the SQL statement(s)
Can anyone offer some ideas, please?