Re: Open MS Word in Access 2007
- From: KADL <KADL@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 3 Sep 2009 16:56:01 -0700
There is so much code, I was trying to narrow down what you would need to
see. There are gosubs and user defined functions, so I hope I didn't miss
anything. The first time the button is clicked, another field combo box
appears for the user to select a word doc that they want to use. when the
user clicks the button again it creates a merge file of the displayed person
and the Word doc opens with the data merged in. First I pasted the important
called function. Note that there are commented out lines in here, too.
Thank you so much for your help!
Function get_Cur_Pbomsword()
Dim xstring As String
On Error GoTo err_get_cur_Pbomsword
get_Cur_Pbomsword = GetSetting(appname:="ICM", Section:="mswordname",
Key:="appname", Default:="25")
If get_Cur_Pbomsword = "25" Then
xstring = DLookup("[msword]", "Probation Officers", "[UserID] =
CurrentUser()")
SaveSetting "ICM", "mswordname", "appname", xstring
get_Cur_Pbomsword = xstring
End If
exit_get_Cur_Pbomsword:
Exit Function
err_get_cur_Pbomsword:
get_Cur_Pbomsword = "err"
GoTo exit_get_Cur_Pbomsword
End Function
Private Sub PrintLetter_Click()
On Error GoTo Err_PrintLetter_Click
Dim inset As Recordset ' inset = "Defendant Cases Qry" table
Dim db As Database
Dim inCriteria As String
Dim x As Variant, stuff As String, Pbo_DefaultPrinterMode As String
Dim DocName As String, DocType As String
Dim casestring As String, Courtstring As String, Judgeinitstring As String
Dim Access_form As String
Const Corr_Letter = "Corr - Letter"
Dim Deftid As Long, CHCCID As Long, Court As String
Dim LinkCriteria As String
Dim Note As String, Trancode As String
Dim crlf As String
Dim Word_command As String, wpdir As String
Dim MyControl As Control
Dim writestat As Integer, writefilenote As Integer
Dim comma As String
Dim qt As String
qt = Chr$(34)
crlf = Chr$(13) & Chr$(10)
If Me![FAL Form id].Visible = False Then
Me![FAL Form id].Visible = True
Set MyControl = Me![FAL Form id]
MyControl.SetFocus
GoTo exit_PrintLetter_Click
End If
Me![PrintLetter].SetFocus
Me![FAL Form id].Visible = False
If IsNull(Me![FAL Form id]) Then
MsgBox "Must select a form or letter first"
GoTo exit_PrintLetter_Click
End If
Access_form = "???"
Set db = CurrentDb()
On Error GoTo PrintLetter_Click_cont1
DocType = DLookup("[DocType]", "FAL Control Table", "[Form ID] =
Forms![Defendant Lookup Form]![FAL Form id]")
On Error GoTo Err_PrintLetter_Click
If DocType = "L" Then
GoSub Link_to_word
Else
GoSub Print_Report
End If
exit_PrintLetter_Click:
Set db = Nothing
DoCmd.SetWarnings True
Exit Sub
Err_PrintLetter_Click:
MsgBox Error$
Resume exit_PrintLetter_Click
PrintLetter_Click_cont1:
GoSub Link_to_word
GoTo exit_PrintLetter_Click
Print_Report:
Access_form = DLookup("[AccessForm]", "FAL Control Table", "[Form ID] =
Forms![Defendant Lookup Form]![FAL Form id]")
writestat = DLookup("[WriteStat]", "FAL Control Table", "[Form ID] =
Forms![Defendant Lookup Form]![FAL Form id]")
writefilenote = DLookup("[WriteFilenote]", "FAL Control Table", "[Form
ID] = Forms![Defendant Lookup Form]![FAL Form id]")
If Access_form <> "not" Then
DoCmd.OpenForm Access_form, , , LinkCriteria
Else
Pbo_DefaultPrinterMode = get_Pbo_PrintPreview()
If get_Pbo_PrintPreview() Then
DoCmd.OpenReport Forms![defendant lookup form]![FAL Form id],
A_PREVIEW
Else
DoCmd.OpenReport Forms![defendant lookup form]![FAL Form id],
A_NORMAL
End If
' add stat
DoEvents
If writestat Then
Deftid = Forms![defendant lookup form]![Deftid]
CHCCID = Forms![defendant lookup form]![chcc
subform].Form![CHCCID]
Court = Forms![defendant lookup form]![chcc subform].Form![Court]
' X = Add_Stat(Corr_Letter, Deftid, CHCCid, Court)
End If
' add file note
If writefilenote Then
Note = ""
Trancode = "LC"
x = Add_Note(Deftid, CHCCID, Note, Trancode)
End If
End If
Print_Report_Exit:
Return
Link_to_word:
GoSub Build_CaseString
DoCmd.SetWarnings False
DocName = "FAL Delete all WW_FAL"
DoCmd.OpenQuery DocName, A_NORMAL, A_EDIT ' CaseString or Casenumbers
DocName = "FAL Deft NEW QRY"
DoCmd.OpenQuery DocName, A_NORMAL, A_EDIT
DocName = "FALDET Delete all WW_FAL"
DoCmd.OpenQuery DocName, A_NORMAL, A_EDIT
DocName = "FALDET Deft NEW QRY"
DoCmd.OpenQuery DocName, A_NORMAL, A_EDIT
GoSub Add_Case_to_WW
' DoCmd.TransferText acExportDelim, "Standard Output", "External Report",
"C:\Txtfiles\April.doc"
' DoCmd.TransferText acExportDelim, "Defendant import", "WW_FAL",
"c:\FALDEFT.TXT", True
' DoCmd.TransferText acExportDelim, "Defendant import", "WW_FALDET",
"c:\FALDET.TXT", True
'------------------------- OLD CODE KEEP KEEP KEEP KEEP KEEP KEEP KEEP
KEEP ----------------------------*
' DoCmd.TransferText acExportDelim, , "WW_FAL", "c:\FALDEFT.TXT", True
'------------------------- OLD CODE KEEP KEEP KEEP KEEP KEEP KEEP KEEP
KEEP ----------------------------*
' Next line outputs an excel spread *** c:\faldeftx
DYN_faldeft
' next line outputs text file to c:\faldeft.txt
write_faldeft
' Word_command = GetSetting(appname:="ICM", Section:="mswordname", _
' Key:="appname", Default:="25")
Word_command = get_Cur_Pbomsword()
If Word_command = "25" Then
MsgBox "ICM unable to Start MS Word. Report this error. Data has
probably been posted correctly. Try starting MS Word manualy and open the
document."
End If
wpdir = get_Pbo_wpdirectory()
stuff = Word_command & " " & qt & wpdir & Me.Form![FAL Form id] & qt
x = Shell(stuff, 1)
' add stat
DoEvents
Deftid = Forms![defendant lookup form]![Deftid]
CHCCID = Forms![defendant lookup form]![chcc subform].Form![CHCCID]
' Court = forms![Defendant Lookup Form]![CHCC Subform].form![Court]
' X = Add_Stat(Corr_Letter, Deftid, CHCCid, Court)
' add file note
Note = ""
Trancode = "LC"
x = Add_Note(Deftid, CHCCID, Note, Trancode)
Return
Build_CaseString:
casestring = ""
Courtstring = ""
Judgeinitstring = ""
Set inset = db.OpenRecordset("Defendant Cases Qry", DB_OPEN_DYNASET,
dbSeeChanges)
inCriteria = "[CHCCID] = " & Forms![defendant lookup form]![chcc
subform].Form![CHCCID]
inset.FindFirst inCriteria
comma = ""
Do Until inset.NoMatch
casestring = casestring & comma & inset![Casenumber]
Courtstring = Courtstring & comma & inset![Court]
' Judgeinitstring = Judgeinitstring & comma & inset![Judgeinit]
' no judge info on case level anymore
comma = ", "
inset.FindNext inCriteria
Loop
inset.close
' Forms![Defendant Lookup Form]![Cases Subform].form![Casenumber]
Return
Add_Case_to_WW:
Set inset = db.OpenRecordset("WW_FAL", DB_OPEN_DYNASET, dbSeeChanges)
inCriteria = "[Deftid] > 0 "
inset.FindFirst inCriteria
If inset.NoMatch Then
Debug.Print "oops"
Else
inset.Edit
inset("Casenumbers") = casestring
inset("Courts") = Courtstring
' inset("Judgeinits") = Judgeinitstring
'no judge info in case file anymore.
inset.Update
End If
inset.close
Return
End Sub
"Gina Whipp" wrote:
The form where the command button is located....
1. Open it Design View
2. Click the Code button located on the Menu Bar (kinda looks like a blue
square)
3. On the Menu Bar select Edit... Select All... back to Edit... Copy...
4. Open new message and Paste here
--
Gina Whipp
"I feel I have been denied critical, need to know, information!" - Tremors
II
http://www.regina-whipp.com/index_files/TipList.htm
"KADL" <KADL@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8BAF7D8E-A014-4EAE-8AC0-2123ED1F3A83@xxxxxxxxxxxxxxxx
I'm not sure what to look for. What is the command or function for caling
MS
Word?
"Gina Whipp" wrote:
Krisse,
We're going to need to see that code... that will go a great way into
seeing
what is happening!
--
Gina Whipp
"I feel I have been denied critical, need to know, information!" -
Tremors
II
http://www.regina-whipp.com/index_files/TipList.htm
"KADL" <KADL@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4CE602F1-A430-435E-A76F-C0547BFB6E35@xxxxxxxxxxxxxxxx
Darn. I check the references used in the 2003 version of the app (on a
2003
installed machine) and it doesn't even use the MS Word obj lib. I
remembered
that when a required reference is missing, that reference is listed
below
the
checked references with the word 'missing' next to it.
I'm still going to go try it tomorrow, but I am not hopeful.
Any other ideas for me to try while I'm there tomorrow?
Thanks,
Krisse
"KADL" wrote:
Thanks, Gina and Daniel. The Word 12.0 object library was indeed
missing. I
added it but I can't test it from the machine I'm on now. I'll be
able
to
test it tomorrow and I'll let you know how it goes.
Thanks again,
KADL
"Daniel Pineault" wrote:
If it is a reference issue as Gina has suggested it could be, you
can
quickly
find out by:
Open the VBE
On the Standard Toolbar, goto Tools - References
Take a look at the top of the listing to see if any are marked as
Missing.
If so you need to scroll through the list of available references
and
select
the version that you have at your disposal.
For instance you might have Microsoft Excel 11.0 Object Library as
missing
and instead you have Microsoft Excel 12.0 Object Library as a
choice.
Give it a shot and let us know.
--
Hope this helps,
Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
"Gina Whipp" wrote:
KADL,
Sounds like a Reference issue... In addition to Daniel's request,
what
version of Word is loading the machine?
--
Gina Whipp
"I feel I have been denied critical, need to know, information!" -
Tremors
II
http://www.regina-whipp.com/index_files/TipList.htm
"KADL" <KADL@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:72F660FB-A68A-4F74-A47F-E2C5ECEFCD65@xxxxxxxxxxxxxxxx
I inherited an unconvertable Access 2003 application in Access
2007
and it
no
longer opens Word where it used to.
A Form button creates a merge file and then using a path and
.doc
name
from
a table used to open (in Access 2003) the Word doc displaying
the
merged
data.
Now the merge file is created but Word doesn't open.
As I read the code, I'm not sure of what command was opening
Word.
Can
you
tell me what that is in Access 2003 and if Access 2007 requires
something
else? Is there perhaps something that needs to be done on the
Word
side?
Thanks!
- Follow-Ups:
- Re: Open MS Word in Access 2007
- From: Gina Whipp
- Re: Open MS Word in Access 2007
- References:
- Open MS Word in Access 2007
- From: KADL
- Re: Open MS Word in Access 2007
- From: Gina Whipp
- Re: Open MS Word in Access 2007
- From: Daniel Pineault
- Re: Open MS Word in Access 2007
- From: KADL
- Re: Open MS Word in Access 2007
- From: KADL
- Re: Open MS Word in Access 2007
- From: Gina Whipp
- Re: Open MS Word in Access 2007
- From: KADL
- Re: Open MS Word in Access 2007
- From: Gina Whipp
- Open MS Word in Access 2007
- Prev by Date: Re: Dates don’t work within WHERE clauses
- Next by Date: Re: Control a Query Data*** with Code
- Previous by thread: Re: Open MS Word in Access 2007
- Next by thread: Re: Open MS Word in Access 2007
- Index(es):