My Assistant
![]() ![]() |
|
|
Mar 12 2012, 08:33 AM
Post
#1
|
|
|
UtterAccess Addict Posts: 199 From: Lisbon - Portugal |
Hi all,
I have a table that has a field called txtPath, on that field I have a path to a certain txt file Record 1 \\sedl\Global\12096\69744A08.txt Record 2 \\sedl\Global\12096\69744A09.txt Record 3 \\sedl\Global\12096\69744A10.txt I need to tell Access to print all of the txt’s on that field using Notepad. Does anyone have an idea how to do this? Tks in advance Luís |
|
|
|
Mar 12 2012, 08:49 AM
Post
#2
|
|
|
UtterAccess Editor Posts: 6,719 From: Capital District, NY, USA |
If notepad is the registered program for handling text files, you can send the filepath through ShellExecute and use "print" as the action string instead of "open"
If notepad is not the registered program, you would a) have to use a commandline argument, if available, to execute notepad in some sort of print mode (I don't this is an option for notepad), or b) open notepad and use the WinAPI to find the window and process the menubar commands (a real pain). You can find a version of ShellExecute at mvps.org/access/api Likewise, search the MSDN for ShellExecute to see which argument is the Action argument, and change mvps.org's example (I forget if it's default/null (&0) or "open", but either way, just change that to "print" instead). hth |
|
|
|
Mar 12 2012, 08:53 AM
Post
#3
|
|
|
UtterAccess Addict Posts: 199 From: Lisbon - Portugal |
Tks jleach,
But for some reason, I can't open mvps.org/access/api website from here (I'm at work) Can you provide the code please? Tks |
|
|
|
Mar 12 2012, 09:16 AM
Post
#4
|
|
|
UtterAccess Editor Posts: 6,719 From: Capital District, NY, USA |
Here's my version, not quite the same as the mvps.org version but it'll work. Put it in a new module and use the following line from some place in your code to print the txt file:
CODE ShellEx "C:\YourFile.txt", seopPrint the code: CODE Option Compare Database Option Explicit Private Declare Function apiShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" _ (ByVal hWnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) _ As Long 'ShowWindow Enum Public Enum eSE_ShowWindow seswHide = 0 seswNormal = 1 seswShowMinimized = 2 seswShowMaximized = 3 seswShowNoActivate = 4 seswShow = 5 seswMinimize = 6 seswShowMinNoActive = 7 seswShowNA = 8 seswRestore = 9 seswShowDefault = 10 seswForceMinimize = 11 seswMax = 12 End Enum 'Operation enum Public Enum eSE_Operation seopOpen = 0 seopPrint = 1 seopExplore = 2 End Enum '============================================================================ == ' NAME: ShellEx ' DESC: Calls ShellExecute API '============================================================================ == 'ErrStrV3.00 Public Function ShellEx( _ sFile As String, _ Optional iOperation As eSE_Operation = seopOpen, _ Optional sParameters As String = "", _ Optional sDirectory As String = "", _ Optional lShowCmd As eSE_ShowWindow = seswNormal, _ Optional lHand As Long = 0 _ ) As Boolean On Error GoTo Error_Proc Dim Ret As Boolean '========================= Dim sOp As String '========================= Select Case iOperation Case seopOpen: sOp = "open" Case seopPrint: sOp = "print" Case seopExplore: sOp = "explore" End Select If Len(sParameters) = 0 Then sParameters = vbNullString If Len(sDirectory) = 0 Then sDirectory = vbNullString Ret = IIf( _ apiShellExecute( _ lHand, sOp, sFile, sParameters, sDirectory, lShowCmd) _ > 32, _ True, False) '========================= Exit_Proc: ShellEx = Ret Exit Function Error_Proc: MsgBox "Error: " & Trim(str(Err.Number)) & vbCrLf & _ "Desc: " & Err.Description & vbCrLf & vbCrLf & _ "Module: basShellExecute, Procedure: ShellEx" _ , vbCritical, "Error!" Resume Exit_Proc Resume End Function hth |
|
|
|
Mar 12 2012, 09:20 AM
Post
#5
|
|
|
UtterAccess VIP Posts: 17,643 From: Don Mills, ON (Canada) |
While Jack's shown you the best way of doing it, it is possible to cheat! (IMG:style_emoticons/default/grin.gif)
CODE Function PrintTextFile(FullPathToFile As String)
Dim strCommand As String strCommand = "notepad.exe /p """ & FullPathToFile & """" Call Shell(strFile, vbHide) End Function |
|
|
|
Mar 12 2012, 09:22 AM
Post
#6
|
|
|
UtterAccess Addict Posts: 199 From: Lisbon - Portugal |
Tks jleach,
I found this code and it does "almost" what I want.... ***** Option Compare Database Option Explicit 'stole from mvps.org/access/api/api0018.htm btw Private Declare Function ShellEx Lib "shell32.dll" _ Alias "ShellExecuteA" _ (ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) _ As Long Public Function PrintContactLinks() On Error GoTo Err_Proc Dim Ret As Boolean Dim rs As DAO.Recordset Set rs = CurrentDb.OpenRecordset( _ "SELECT tbl3270.REF, tbl3270.PATH FROM tbl3270 ORDER BY tbl3270.REF") If rs.RecordCount <> 0 Then rs.MoveFirst While Not rs.EOF ShellEx hWndAccessApp, "print", rs("PATH"), vbNullString, vbNullString, 1 DoEvents rs.MoveNext Wend End If Ret = True Exit_Proc: rs.Close: Set rs = Nothing PrintContactLinks = Ret Exit Function Err_Proc: MsgBox "Error in Module.PrintContactLinks!" Resume Exit_Proc End Function ***** Tks again.... Cheers Luis |
|
|
|
Mar 12 2012, 09:28 AM
Post
#7
|
|
|
UtterAccess Editor Posts: 6,719 From: Capital District, NY, USA |
While Jack's shown you the best way of doing it, it is possible to cheat! (IMG:style_emoticons/default/grin.gif) CODE Function PrintTextFile(FullPathToFile As String) Dim strCommand As String strCommand = "notepad.exe /p """ & FullPathToFile & """" Call Shell(strFile, vbHide) End Function I didn't know there was a print switch for notepad. Thanks Doug! Louis - are you aware that PATH as a fieldname is a reserved word? You might want to change that... Cheers, |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 24th May 2013 - 11:32 AM |