Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    100

    Unanswered: I want to print freely

    Hello,

    I want to print out with VBA for Access. I want to do something like that:

    APrinter.Print "NAME: " & x.Subitems(1) & Chr(13)
    APrinter.Print "Code: " & x.Subitems(2) & Chr(13)
    APrinter.Print "Working with Campbells: " & x.Subitems(3) & Chr(13)
    APrinter.Print "Remark: " & x.Subitems(4) & Chr(13)
    APrinter.Print Chr(13)

    Printer seems not to exist for VBA for Access.

    It will be nice to be able to create a temporary text file (delete it after print) and then print it. In this way, maybe, it is possible to have the printer window options before print.

    Any help? Does Somebody have experience with that?

    Or at least any website with help source code or something? I am completely lost?

    Thank you.
    Last edited by pipeio; 05-11-04 at 09:18.

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Quote Originally Posted by pipeio
    Hello,

    APrinter.Print "NAME: " & x.Subitems(1) & Chr(13)
    APrinter.Print "Code: " & x.Subitems(2) & Chr(13)
    APrinter.Print "Working with Campbells: " & x.Subitems(3) & Chr(13)
    APrinter.Print "Remark: " & x.Subitems(4) & Chr(13)
    APrinter.Print Chr(13)
    Why don't you use the

    Open "C:\Temp\PrintoutPut.txt" For Output As #11
    Print #11, "NAME: " & x.Subitems(1) & vbNewLine
    Print #11, "Code: " & x.Subitems(2) & vbNewLine
    Close


    Then use the Shell command to run the Dos command
    Print

  3. #3
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    100
    Thanx, I will try and I will tell you ...

  4. #4
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    100
    Ok, I have a question. I don't know in which PC the user is going to execute the application, maybe he doesn't have permission to write in the folder I indicate.
    What can I do?
    By the way, I am looking for how to execute the print dos command with the shell library. Any website which help me?

    Thanx a lot

  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    Print will be used as follow
    Print [/ D : printer] [[Drive:] [Path]FileName[....]]

    About the permission you should show the user a message that he has no permmision to write to this drive and let him enter or choose his own.

  6. #6
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Further more, every user has permission to write on his DeskTop , so you can use it as a Folder to write your TempFile
    Good luck,

    I have to go now

  7. #7
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    100
    Hey Hammbakka, thanks for your help. But the Print you told me doesn't work. Now that I have the PrintOut.txt in my system, how can I print it from VBAccess? uffffff, so difficult, I am searching and searching, it must be easy

  8. #8
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    You can use the SendKey function. Wait a littel, I'll test some code and send it to you.

  9. #9
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    Again here is the code, I testd it, and functions

    PHP Code:
      Private Sub cmd_printTxt_Click()
        
    Call Shell("notepad.exe c:\Temp\yourFile.txt"vbNormalFocus)
        
    SendKeys "%{D}"True  '  Datei
        SendKeys "{D}", True  ' 
    Drucken
      End Sub 
    Since I use a german office I used %{D} for ALT+Datei
    You shoud change it to %{P} if you use english office or another combination according to your Office type

  10. #10
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    100
    Thanks a lot hammbakka. I got it using Ctrl+P. So the window of the printer is open, and then you print, perfect!
    Ok, now I am struggling my brains in that: I don't want to leave the txt I print in the system, I want to delete it, cause it's not very nice that a file appears in the desktop like a magic event and stays there. So, do you have an idea of how can I delete it after print. Cause the thing is, I have a function which deletes files, but I cannot delete the file since is open to print. If I use SendKeys ALT+F4 after SendKeys Ctrl+P then it closes the printer window, cause is the printer window which has the focus.
    So, do you have any idea? Maybe it is not very good to do all this actions by means of VB, I have the hazard that the user close the aplication or something happens during the development of all these actions and my job fails.

    The problem is that I haven't found any other way to print, because the Printer object doesn't exist in VB for Access.

    Please, stay with me!! I am in mountain of shit. :-)
    Last edited by pipeio; 05-12-04 at 05:28.

  11. #11
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Just wait, I'll check the FileSystem Object. Perhaps you can try this too

  12. #12
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Sorry, I have no Idea how to do that, because when the print window comes, and you close it after printing, you will lose the control from your vbAccess. You must do it another way. What was wrong with the print Command?

  13. #13
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    100
    Thanks, I wait :-)

  14. #14
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    100
    The print command doesn't exist in VBA, neither the Printer object nor data type.

  15. #15
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Arrow

    Another idea,
    why don't you try to import this text file in a Table (this will be as only one Record, because it is not comma separated values) then make a report, print it and then delete the .txt file from your Desktop.
    Or
    there is no need to write your data in a text file, just write them to a table then make the reoport and print it

Posting Permissions

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