Results 1 to 3 of 3

Thread: Printing TEXT document

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    Chennai,INDIA
    Posts
    6

    Printing TEXT document

    HOW TO PRINT text document using shell command without opening the file

    Hi friends,
    I am having problem with printing the text document. i here added the vb code for clarification.
    VB Code:
    1. repobno2.ExportReport key_def_Text, "F:\Vsquar system on gopinath\badgereport", True, False, rptRangeAllPages
    2. Dim conn As New ADODB.Connection
    3. Dim rsss As New ADODB.Recordset
    4. conn.Open ("Provider=SQLOLEDB.1;User ID=gs;password= gs123;Initial Catalog=Visitor;Data Source=bdnet")
    5. rsss.Open "SELECT TSno, Tname, Tcom, Taddr, TPhno, TVeno, TCatgry, TDept, Tcont, TReas, Tin, Tbadgno, Tcostcenter, remark FROM Timein where TSno = 1", conn, adOpenDynamic, adLockOptimistic
    6. Dim name, company, address, vehicleno, costcenter, department, category, contact, remarks, reason As String
    7. Dim Serialno, Bagdenophoneno As Long
    8. Dim TimeIn As Date
    9. Dim phoneno As Variant
    10. Do Until rsss.EOF
    11. Serialno = rsss.Fields("Tsno")
    12. name = rsss.Fields("tname")
    13. company = rsss.Fields("Tcom")
    14. address = rsss.Fields("Taddr")
    15. phoneno = rsss.Fields("Tphno")
    16. vehicleno = rsss.Fields("Tveno")
    17. category = rsss.Fields("Tcatgry")
    18. department = rsss.Fields("Tdept")
    19. costcenter = rsss.Fields("Tcostcenter")
    20. contact = rsss.Fields("Tcont")
    21. reason = rsss.Fields("Treas")
    22. TimeIn = rsss.Fields("tin")
    23. badgeno = rsss.Fields("Tbadgno")
    24. remarks = rsss.Fields("remark")
    25. rsss.MoveNext
    26. Loop
    27. rsss.Close
    28. Open App.Path & "\Output\badgereport.txt" For Output As #1
    29.     Print #1,
    30.     Print #1, Tab(25); "Sundaram Clayton Limited"; Tab(60); Date
    31.     Print #1, Tab(35); "DCD, PADI"
    32.     Print #1, Tab(2); "--------------------------------------------------------------------------------"
    33.     Print #1, Tab(35); "|"
    34.     Print #1, Tab(2); "Serial No:"; Tab(15); Serialno; Tab(35); "|";
    35.     Print #1, Tab(35); "|"; Tab(50); "VISITOR'S  INSTRUCTIONS"
    36.     Print #1, Tab(2); "Badge No:"; Tab(15); badgeno; Tab(35); "|";
    37.     Print #1, Tab(2); "--------------------------------------------------------------------------------"
    38. 1
    39.     Print #1, Tab(2); "Name"; Tab(15); name; Tab(35); "|"; Tab(36); "1. This pass is valid  to permitted area only."
    40. 2
    41.     Print #1, Tab(2); "Company:"; Tab(15); company; Tab(35); "|"; Tab(36); "2. Declare your personal properties Laptop, "
    42.     Print #1, Tab(35); "|"; Tab(39); "Computers,CD's, Floppies, Drawings,"
    43.     Print #1, Tab(35); "|"; Tab(39); "Components,etc., to security at the entry"
    44.     Print #1, Tab(35); "|"; Tab(39); "itself and get Security endorsment."
    45. 3
    46.     Print #1, Tab(2); "Address"; Tab(15); address; Tab(35); "|"; Tab(36); "3. Collect your pass and surrender the same"
    47.     Print #1, Tab(35); "|"; Tab(39); "at security at exit."
    48. 4
    49.     Print #1, Tab(35); "|"; Tab(36); "4. Adhere to safety rules and regulation when "
    50.     Print #1, Tab(35); "|"; Tab(39); "you are in factory premises."
    51. 5
    52.     Print #1, Tab(35); "|"; Tab(36); "5. Factory is non-smoking zone. Kindly refrain "
    53.     Print #1, Tab(35); "|"; Tab(39); "from smoking."
    54. 6
    55.     Print #1, Tab(2); "Phone No:"; Tab(15); phoneno; Tab(35); "|"; Tab(36); "6. Photography strictly prohibited. In case "
    56.     Print #1, Tab(35); "|"; Tab(39); "Camera is brought, please deposit with "
    57.     Print #1, Tab(35); "|"; Tab(39); "security at entry gate."
    58. 7
    59.     Print #1, Tab(2); "Vehicle No:"; Tab(15); vehicleno; Tab(35); "|"; Tab(36); "7. Cell phones are not allowed inside the "
    60.     Print #1, Tab(35); "|"; Tab(39); "factory premises,please deposit the same "
    61.     Print #1, Tab(35); "|"; Tab(39); "with the security at the entry gate."
    62.  
    63.     Print #1, Tab(2); "Category"; Tab(15); category; Tab(35); "|"
    64.     Print #1, Tab(2); "Department:"; Tab(15); department; Tab(35); "|"
    65.     Print #1, Tab(2); "Cost Center:"; Tab(15); costcenter; Tab(35); "|"
    66.     Print #1, Tab(2); "Contact:"; Tab(15); contact; Tab(35); "|"
    67.     Print #1, Tab(2); "Reason"; Tab(15); reason; Tab(35); "|"
    68.     Print #1, Tab(2); "Remarks:"; Tab(15); remarks; Tab(35); "|"
    69.     Print #1, Tab(2); "Time In:"; Tab(15); Format$(TimeIn, "dd - MM - YYYY"); Tab(35); "|"
    70.     Print #1, Tab(2); "Time Out:"; Tab(35); "|"
    71.     Print #1, Tab(35); "|"
    72.     Print #1, Tab(2); "--------------------------------------------------------------------------------"
    73.     Print #1, Tab(35); "|"
    74.     Print #1, Tab(35); "|"
    75.     Print #1, Tab(2); "Issuing"; Tab(20); "Contact Person"; Tab(35); "|"
    76.     Print #1, Tab(2); "Authority"; Tab(20); " Signature"; Tab(35); "|"
    77.     Print #1,
    78.     Print #1,
    79.     Print #1,
    80.  
    81.     pglen = pglen + 36
    82.      While Not rs.EOF
    83.         sal = 0: empnm = "": acno = ""
    84.         empnm = rs.rdoColumns(0)
    85.         acno = rs.rdoColumns(1)
    86.         sal = rs.rdoColumns(2)
    87.         Print #1, Tab(2); sno; Tab(6); empnm; Tab(33); acno; Tab(50); justn(Format(sal, "####0.00"), 9)
    88.         pglen = pglen + 2
    89.         rs.MoveNext
    90.         If sno Mod 13 = 0 Then
    91.             pg = pg + 1
    92.         If pglen > 65 And Not rs.EOF Then
    93.             Print #1, Tab(65); "Contd..."
    94.             pg = pg + 1
    95.             pglen = 0
    96.             pglen = pglen + 5
    97.  
    98.       Close #1
    99.       z = Shell("C:\WINDOWS\notepad.exe " & App.Path & "\Output\badgereport.txt", vbMaximizedFocus)
    Here i am opening the document and then i am printing.

    waiting for reply.
    Last edited by si_the_geek; Jul 11th, 2006 at 03:23 PM. Reason: added VBCode tags for readability

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Printing TEXT document

    Moved from FAQ forum, and added VBCode tags so we can read the code more easily.

    The simple answer is that you do not use Shell, but instead use ShellExecute, which allows you to run the methods on a file that are shown when you right-click on it in Explorer (such as Open/Edit/Print).

    This is untested, but will at least be close to what you want:
    VB Code:
    1. 'in Declarations section:
    2. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    3.   ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    4.   ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    5. Const SW_SHOWNORMAL = 1
    6.  
    7. 'The code:
    8.     ShellExecute Me.hwnd, "Print", App.Path & "\Output\badgereport.txt", vbNullString, "C:\", SW_SHOWNORMAL

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Printing TEXT document

    Or you could use the Printer object and print the file directly from VB, without using Notepad. There are plenty of examples in the forum.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width