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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide Access Window

Status
Not open for further replies.

techie99

Programmer
Apr 24, 2003
60
US
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
 
I really don't know too much about word automation but I've seen the opendatasource called with an ODBC datasource.

DSN:=dsnname where you have NAME:=dbpath I believe.

It seems like if you set up an ODBC datasource and used that instead of just a path to the .mdb Word wouldn't have to actually open Access to get to the data.

You do that in the control panel. There is an Icon labeled OBDC Data Sources. On the first page highlight MS access and click Add, next page highlight MS Access driver and click Finish.

On the next page give it a name (that what you'll put in DSN:=) then under database click select and just browse to your mdb file.

If there is a password on the mdb and you don't want the user to have to enter it click the advanced tab and put in admin for user name and the password.

Should work.






(in control panel ODBC connections) specify for your Access mdb and used the name of that for DSN (instead of the path you have now) Word would not have to actually open Access to get the data.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top