I'm using Visual Basic 6.0 to generate folder labels in Microsoft Word 97 with the data source for the labels being a table in a Microsoft Access 97 database. The labels are generating fine, my only problem is that an instance of Access is started and remains open until the Word Document is created, thereby enabling the users to play around with the Access window, which is highly undesirable. Is there any way for me to hide that window while the labels are being generated? If not, how can I re-do this so I get the results I want?
Dim dbpath As String
dbpath = App.Path & "\cvb.mdb"
Dim oApp As Word.Application
Dim oDoc As Word.Document
Set oApp = CreateObject("Word.Application"
Set oDoc = oApp.Documents.Add
With oDoc.MailMerge
With .Fields
oApp.Selection.TypeText "Victim: "
.Add oApp.Selection.Range, "Victim_FName"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, "Victim_LName"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, "Expr1"
oApp.Selection.TypeParagraph
oApp.Selection.TypeText "Defendant: "
.Add oApp.Selection.Range, "Defendant_FName"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, "Defendant_LName"
End With
Dim oAutoText As Word.AutoTextEntry
Set oAutoText = oApp.NormalTemplate.AutoTextEntries.Add("MyLabelLayout", oDoc.Content)
oDoc.Content.Delete
.MainDocumentType = wdMailingLabels
.OpenDataSource Name:=dbpath, ReadOnly:=True, SQLSTATEMENT:="SELECT CrimeVictim.*, Year([Date_Time]) AS Expr1 From CrimeVictim WHERE (((CrimeVictim.Date_Time) Between #" & Me.DTPicker1.Value & "# AND #" & Me.DTPicker2.Value & "#) AND ((CrimeVictim.New)=Yes))"
oApp.MailingLabel.CreateNewDocument Name:="5366", Address:="", _
AutoText:="MyLabelLayout", LaserTray:=wdPrinterManualFeed
.Destination = wdSendToNewDocument
.Execute Pause:=False
oAutoText.Delete
End With
oDoc.Close False
oApp.Visible = True
oApp.NormalTemplate.Saved = True
Dim dbpath As String
dbpath = App.Path & "\cvb.mdb"
Dim oApp As Word.Application
Dim oDoc As Word.Document
Set oApp = CreateObject("Word.Application"
Set oDoc = oApp.Documents.Add
With oDoc.MailMerge
With .Fields
oApp.Selection.TypeText "Victim: "
.Add oApp.Selection.Range, "Victim_FName"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, "Victim_LName"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, "Expr1"
oApp.Selection.TypeParagraph
oApp.Selection.TypeText "Defendant: "
.Add oApp.Selection.Range, "Defendant_FName"
oApp.Selection.TypeText " "
.Add oApp.Selection.Range, "Defendant_LName"
End With
Dim oAutoText As Word.AutoTextEntry
Set oAutoText = oApp.NormalTemplate.AutoTextEntries.Add("MyLabelLayout", oDoc.Content)
oDoc.Content.Delete
.MainDocumentType = wdMailingLabels
.OpenDataSource Name:=dbpath, ReadOnly:=True, SQLSTATEMENT:="SELECT CrimeVictim.*, Year([Date_Time]) AS Expr1 From CrimeVictim WHERE (((CrimeVictim.Date_Time) Between #" & Me.DTPicker1.Value & "# AND #" & Me.DTPicker2.Value & "#) AND ((CrimeVictim.New)=Yes))"
oApp.MailingLabel.CreateNewDocument Name:="5366", Address:="", _
AutoText:="MyLabelLayout", LaserTray:=wdPrinterManualFeed
.Destination = wdSendToNewDocument
.Execute Pause:=False
oAutoText.Delete
End With
oDoc.Close False
oApp.Visible = True
oApp.NormalTemplate.Saved = True