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

Using VBA code 1

Status
Not open for further replies.

PAULCALLAGHAN

Technical User
Sep 4, 2001
165
CA
I would like to know how to use vba code in an Access database. I'm using Access 2000.

I use tables, queries, reports and macros but I have not made use of vba code.

I'm in the same boat as mahaishan, who sent a thread earlier today called "How to Email reports as PDF files."

Can someone please lend us a hand in getting this code into our database and working the way it should?

 
Paul,
There are lots of samples of code in these forum. Most of the wizards like open or close a form or report will write code for you. You can also convert a macro to code.

If you give us a simple example of what you want to do with code, I'm sure someone will help you with it.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
One of the best ways to learn code in Access or Excel is to build a Macro and then convert it to VBA. Then go to the Visual Basic editor and see the created code along with comments and error handling. One of the key things is to learn what event you need to attach code to. The OnOpen and OnCurrent events of a form for example are common places to put code, but are different depending on what you are trying to accomplish.

LJ

LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
The code that I am trying to use comes from this web-site,


I want to know how I can put this code to work. As I mentioned earlier I am a novice in the VBA arena. Any help would be greatly appreciated.

There may be a secondary problem here.

The author of this code mentions use of the Adobe PDF Writer, which is very old, and was written for Windows 95. Will it still work for me?

I'm using Access 2000 on a Windows XP computer.

If I have to obtain a newer PDF writer how do I adjust the code for it?
 
I'm not sure if the code will work with newer versions of Adobe and Windows.

In general, you would create a new, blank module in your database. Copy the code from the web page (you may want to use the "copy-and-paste friendly" version) and paste it into the new module window. Then test whether the code compiles by clicking Debug->Compile...

Then, I would use the command button wizard to create a "run report" command button. Replace the
Code:
    Dim stDocName As String

    stDocName = "YourReportName"
    DoCmd.OpenReport stDocName, acPreview
with
Code:
    Dim stDocName As String

    stDocName = "YourReportName"
    Call RunReportAsPDF(stDocName, "C:\", "YourReport.pdf")
You would replace C:\ and YourReport.pdf with whatever.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top