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

suspend access, edit a word template/document, return to access

Status
Not open for further replies.

jmpWashDC

Technical User
Mar 19, 2002
35
US
Hi!
This is a great forum!! The people who post responses to questions are clearly very skilled!!
here's another one for everyone.
I need to call a word template from Access and allow the user to type whatever they feel like typing...
Some of the examples I've seen in various books smash it all together, a report & a chart & a table etc...
I think a command like
"Do/While MSWord is open, just hang out and wait until the user closes the document they just edited" would work.
(hopefully they're smart enough to save it)

With my admittedly limited VBA skills, I don't know how to construct the loop correctly, but I know the VBA code to go and get the document from Access is:

.Documents.Add "C:\directory\blahblah\Fax.dot"
.Visible = True
.Selection.GoTo wdGoToBookmark, Name:="FaxToLine"

It's at this point where the user will begin to type whatever they feel like typing...
and when that's finished, I want to make Access do this neat little trick:
With appWord
.Documents.Open "C:\directory\blahblah\FAX.doc"
.Visible = False
appWord.ActiveDocument.PrintOut
End With


So how do I tell Access to wait?
should I just tell it to count to 1 Google very slowly? haha, that's not funny
JMP


 
Written by Terrry Kraft and found on Dev Ashish's web site I store this routine in all my projects when I am going to shell to programs while in Access, this will cause Access to suspend itself until you are done with any application or DOS batchfile. For exeample, I had to write a routine that would use Close-up to remotely call several plants and download daily output data, once downloaded and after the routine returned control to Access my vba code would continue by converting the data and then import it into several Access tables.

Copy this code into a module and then when you need it you can:

Call Shellwait(path & program to run, window type)

'***************** Code Start ******************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Terry Kreft
Private Const STARTF_USESHOWWINDOW& = &H1
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long
' Initialize the STARTUPINFO structure:
With start
.cb = Len(start)
If Not IsMissing(WindowStyle) Then
.dwFlags = STARTF_USESHOWWINDOW
.wShowWindow = WindowStyle
End If
End With
' Start the shelled application:
ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
End Sub

'***************** Code End ****************

Have fun,
Bruce Gregory
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top