Printing more than selected.

  • Thread starter Thread starter doug d via AccessMonster.com
  • Start date Start date
D

doug d via AccessMonster.com

I made a combo box in a form in Access and I put a print button under it. As
of now I have two choices in the combo box ( ABF Systems and Central
Transport). When using the print button I want it to print out three
seperate word files for the chosen combo box option. I am able to print the
first option which is ABF Systems with no problem. However when I print the
second option (Central Trasnport) it print both the ABF Word files and
Central Transport files. How do I stop it. This is the VB code I am using
for the print button. please help I am so close.

Private Sub print_Click()
If Combo1_AfterUpdate = ABF_Systems Then
Set wordobj = CreateObject("Word.Basic")
wordobj.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
2005 Profiles\abf 2005.doc"
wordobj.fileprint
wordobj.filesave
wordobj.FileClose (1)
Set wordobj = Nothing
Set wordobj = CreateObject("Word.Basic")
wordobj.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
DAILY TASKS\ABF\ABF DAILY TASKS.doc"
wordobj.fileprint
wordobj.filesave
wordobj.FileClose (1)
Set wordobj = Nothing
Set wordobj = CreateObject("Word.Basic")
wordobj.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
DAILY TASKS\ABF\ABF CONTACTS.doc"
wordobj.fileprint
wordobj.filesave
wordobj.FileClose (1)
Set wordobj = Nothing
End If

If Combo1_AfterUpdate = Central_Transport Then
Set wordobj = CreateObject("Word.Basic")
wordobj.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
2005 Profiles\Central Transport 2005.doc"
wordobj.fileprint
wordobj.filesave
wordobj.FileClose (1)
Set wordobj = Nothing
Set wordobj = CreateObject("Word.Basic")
wordobj.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
DAILY TASKS\CENTRAL TRANSPORT\CTII DAILY TASKS.doc"
wordobj.fileprint
wordobj.filesave
wordobj.FileClose (1)
Set wordobj = Nothing
Set wordobj = CreateObject("Word.Basic")
wordobj.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
DAILY TASKS\CENTRAL TRANSPORT\CTII CONTACTS.doc"
wordobj.fileprint
wordobj.filesave
wordobj.FileClose (1)
Set wordobj = Nothing
End If
End Sub
 
This line doesn't make much sense:
If Combo1_AfterUpdate = ABF_Systems Then
You are referencing a Sub, not a function or a varialbe, so I am suprised it
works at all. I think it should be:
If Combo1 = "ABF_Systems" Then

Also, I think you might speed up your code a little with some minor changes.
You create and destroy the Word object repeatedly which can be time
consuming. Try this:

If Combo1_AfterUpdate = ABF_Systems Then
Set wordobj = CreateObject("Word.Basic")
With wordobj
.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
" _
& "2005 Profiles\abf 2005.doc"
.fileprint
.filesave
.FileClose (1)
.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
" _
& "DAILY TASKS\ABF\ABF DAILY TASKS.doc"
.fileprint
.filesave
.FileClose (1)
.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\" _
& "DAILY TASKS\ABF\ABF CONTACTS.doc"
.fileprint
.filesave
.FileClose (1)
End With
Set wordobj = Nothing
End If
 
Back
Top