Solved

Printing from VB

Posted on 2000-02-18
8
153 Views
Last Modified: 2010-05-02
Hi,
  I am interested in a program that will check files into a directory and print their files.
  The problem is that I don´t know how to check a file (for example .doc) and print it automaticly. Is it posible?.

  Can you tell me how to do it or point me somewhere?.

Thks!.

Alejandro Acosta A.
0
Comment
Question by:aacosta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2536030
See the microsoft KB article:

HOWTO: Use ShellExecute to Launch Associated File (32-bit)
http://support.microsoft.com/support/kb/articles/Q170/9/18.asp?LNG=ENG&SA=MSDN&FR=1 


In the example you will see the line:

   StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
          "", "C:\", SW_SHOWNORMAL)
     

If you change the "Open" to "Print" in this line, it will print the document to the default printer using the native application that the file belongs to.  For example, a .DOC file is associated with Word.  This will print the document through word...


Cheers!
0
 
LVL 14

Accepted Solution

by:
mcrider earned 100 total points
ID: 2536064
By the way, if you dont want to have the application visible, you would change that line to:

   StartDoc = ShellExecute(Scr_hDC, "Print", DocName, _
          "", "C:\", 0)



Cheers!
0
 
LVL 6

Expert Comment

by:Marine
ID: 2536105
Its going to be a few more lines then mcrider proposed. Yes you would need to use ShellExecute to print this but to check files you would need something else. I'll see if i can find something for you to solve this. Can i do something like this. Put all the listed files from a directory into a FileList control and then when you click on that file you will print it is that good enough ?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:mcrider
ID: 2536184
I am assuming that aacosta knows how to select the files that are to be printed...  The problem was actually PRINTING the files...

If that was too big of an assumption, I'm sorry...

There are so many ways to select a file(s)...  It all depends on what you want your interface to look like.

You can use the CommonDialog control to select the file(s)...

You can use the DriveListbox DirListbox and FileListbox to select the drive/directory/file...

You can use the Dir statement to get the files in a directory...


All of these are WELL DOCUMENTED in the VB Help file.


aacosta, If you need any more information, let me know.



Cheers!

0
 
LVL 1

Author Comment

by:aacosta
ID: 2536225
Hi again.
  The document at http://support.microsoft.com/support/kb/articles/Q170/9/18.asp?LNG=ENG&SA=MSDN&FR=1 was great!. I already used the code and work great.

  Can you tell me in addition how to get the files that are into a directory?.

Thanks.

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2536286
aacosta,

Thanks for the points! Glad I could help...

In my previous comment I mention several ways to get files... Do you have any idea which method you want to use?? (CommonDialog, FileListBoxes, or the DIR Statement??)


Cheers!
0
 
LVL 1

Author Comment

by:aacosta
ID: 2536404
I think dir Statement is ok.

I would like to print all the files that are into a directory and then move them to another directory. What is the best way?.

I dont want you to do my Job, I just need a help.

Thanks again :-)
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2536451
This code will show all of the files in the directory c:\windows\desktop to the debug window...

    Dim lFileName As String
    lFileName = Dir("c:\windows\desktop\*.*")
    Do While Not lFileName = ""
        Debug.Print lFileName
        lFileName = Dir()
    Loop


To move the files, you can use the FileCopy statement to copy the files to where you want it to go and then use the Kill statement to delete the original file...


Cheers!

0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question