Report Save As PDF (if data is entered)

  • Thread starter Thread starter Deleted member 134417
  • Start date Start date
D

Deleted member 134417

Guest
Hey guys,
I have a report that has multiple clients on each page. In the report, some clients have data for a specific date while others do not.
I would like to be able to Save As PDF each page to a specified folder but only if that client has data in the report. I am currently doing this in Excel, but would like to move my data and reports over to Access. My Excel VBA code is:

Sub SaveAsPDF()

Dim ws As Worksheet

For Each ws In Worksheets
If ws.Range("B66").Value <> "" And _
ws.Name <> "Notes" And _
ws.Name <> "Lookups" Then

ws.Activate

ws.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C:\Users\callen\Desktop\PDF\" & ws.Name & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next ws

End Sub

Which says if B66 is empty then don't Save As PDF.
Is this possible to do in Access?
I'm very new to Access and have never used VBA in it before.
I would like to be able to create a button in a form that when I click it will run this code.
Cheers
 
In Microsoft Access you don't think about your data as being pages, you think about it as being a continuous list.

The general way to extract data is to ask a question like "which part of this list do I want?"

In your case you would say I want this "customer" where this date = X.

You would ask this question with an SQL statement something like:- Select fld1, fld2 From tblMyTable Where Customer = "Fred" and myDate <> date

A further requirement "If there are no results then I do not want to print the report."

You would count the results returned by the above query and if the count was 0 then you would not create the report.

You also want to ask the question, not for just one customer but for each customer.

To achieve this you would use an SQL statement which gathers the customer names then you would put this record set into a record set loop and interrogate each record in turn.

So your original question is now broken down into several elements the first element being:-

"In your case you would say I want this "customer" where this date = X."

Once you have achieved this you can then concentrate on solving the next element and once you have an understanding of all the elements you can draw it together to produce the result you want.
 

Users who are viewing this thread

Back
Top Bottom