Solved

Further automation on reports that are automatically created in .SNP Format based on a table

Posted on 2004-10-20
7
254 Views
Last Modified: 2008-03-06
I have some code behind a button that outputs a series of reports....my code is rather long because I just copied and pasted the same code over and over:

DoCmd.OpenReport stDocName, acViewNormal, , "[PartID] = 1234"
DoCmd.OpenReport stDocName, acViewNormal, , "[PartID] = 1235"
DoCmd.OpenReport stDocName, acViewNormal, , "[PartID] = 1236"
etc etc etc

What I would like to do is create a new table that only lists the partId's that I run reports on.   How could I create the same code to output the same reports by reading the first record in the table and using that value to ouput the report with PartID = value in record 1...then going to record 2...etc etc.

I know it is probably easy, but im stuck.
0
Comment
Question by:robbdfw
[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
7 Comments
 
LVL 2

Assisted Solution

by:AngelinoM
AngelinoM earned 50 total points
ID: 12359197
Create a recordset to query your table and then put
Recordsetname.movefirst
While not Recordsetname.EOF
   DoCmd.OpenReport stDocName, acViewNormal, , "[PartID] = " & RecordsetName!FieldName
   Recordsetname.movenext
wend
0
 
LVL 77

Expert Comment

by:peter57r
ID: 12359200
Hello robbdfw,

Base you report on a query that selects based on matches in the current source and the (new) parts list table.

Add the current source table/query and the new table to a new query and join them on partid save as a new query (q1 or whatever)
Change the report's recordsource to the new query by displaying the report's properties and selecting the new query (q1).


Pete
0
 
LVL 36

Accepted Solution

by:
SidFishes earned 250 total points
ID: 12359807
if you place this code behind a button, it will loop thru all products in your table and output snp's


Private Sub cmdCompile_Click()

Dim strSQL
Dim maxCount  As Long
Dim currCount, currDone As Integer
Dim currdonePct As Integer
Dim x

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
strSQL = "SELECT * from [tblProducts] where discontinuedyn = false and productidupc between 1 and 99999"
Set rst = dbs.OpenRecordset(strSQL)
With rst
      maxCount = .RecordCount
      currCount = .RecordCount
      .MoveFirst
While Not .EOF
      pubProductIDupc = !ProductIDupc
      DoCmd.SelectObject acReport, "RPTCaseLAbels", True
      DoCmd.OutputTo acOutputReport, "RPTCaseLabels", "Snapshot Format", "\\server\snps\case\" & pubProductID & ".snp"
      currCount = currCount - 1
      currDone = maxCount - currCount
      x = currDone / maxCount * 2 'for us and cdn
      currdonePct = CInt(x * 100)
      me!Status.caption = currdonePct
                doEvents
      .MoveNext
Wend
.Close
MsgBox "Labels Compiled"
End With
Set rst = Nothing
Set dbs = Nothing
End Sub

to specify a range just change the sql and add 2 text boxes to your for startRNG and EndRNG

strSQL = "SELECT * from [tbl products] where discontinuedyn = false and productidupc between " & me!startRNG & "and" & Me!EndRNG





0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 36

Expert Comment

by:SidFishes
ID: 12359819
obviously criteria like discontinuedyn could be changed to whatever is appropriate
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 12359959
oh...and you'd need a label called Status for the progress indicator (if you want it )

the benefit to this approach is that you can do any range of reports without manually creating each line docmd.openreport like you are currently doing...
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 12360142
err...and i should point out that this code outputs to snp format ...you can change the OutputTo
to any of the following

acFormatASP
acFormatDAP
acFormatHTML
acFormatIIS
acFormatRTF
acFormatSNP
acFormatTXT
acFormatXLS

or change outputTo to PrintOut if you want multiple copies

   DoCmd.SelectObject acReport, "RPTCaseLAbels", True
     DoCmd.PrintOut ,,,2

or just use

Docmd.openreport "MyReport", acViewNormal

0
 

Author Comment

by:robbdfw
ID: 12363813
Sid...That code rocked... thanks for all the info....some points to you too Angelino

0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

719 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