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 sheet 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
:
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
I'm not sure what to look for. What is the command or function for
caling
MS
Word?
:
Krisse,
We're going to need to see that code... that will go a great way
into