473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

have dynamic report destination/name but want to improve it

I hope I have followed the posting guidelines; apologies from a neophyte if not, and please correct me. I'm self-taught in VB and have reached my limit, so I'm looking for help. I am dealing with multiple permutations: source report, report name, destination, etc. I've created a form where the user selects options; I have functional code (thanks in part to postings here) but am trying to pull out repetitive portions into a public sub so if there are changes to the main variables I only have to make them once. Here's the relevant functional code:
Expand|Select|Wrap|Line Numbers
  1. ' creating dynamic report output destination and name
  2. ' %O = output drive, %R = responsible team, %T = term, %Y = academic year, %D = date
  3.  
  4.     Dim strReportName As String
  5.  
  6.     strReportName = "%O\Internal_%RByInstructor_%T%Y_%D.pdf"
  7.  
  8.     strReportName = Replace(strReportName, "%O", IIf(Forms!frmMainMenu!optgrpDestination = 1, "H:", "O:"))
  9.     strReportName = Replace(strReportName, "%R", Switch(Forms!frmMainMenu!optgrpResponsibleTeam = 1, "All", Forms!frmMainMenu!optgrpResponsibleTeam = 2, "Education", Forms!frmMainMenu!optgrpResponsibleTeam = 3, "Practice", Forms!frmMainMenu!optgrpResponsibleTeam = 4, "Research"))
  10.  
  11.     strReportName = Replace(strReportName, "%Y", Me.cboYear)
  12.     strReportName = Replace(strReportName, "%T", Me.cboTerm)
  13.     strReportName = Replace(strReportName, "%D", Format(Date, "yy-mm-dd"))
My problem is that I have to repeat this for each of 6 reports (internal/external and by course/by instructor/ by team). The two other variables fall where this snippet has \Internal (following %O) and ByInstructor_ (between %R and %T). I tried making this code (minus the line with those variables) a public sub and calling it from a private sub but I can't get it to work. In "Public Sub DynamicReportName()" I changed the line with variables to read

strReportName = "%O%I%R%N%T%Y_%D.pdf"

but left the rest of the code defining the variables the same. I confirmed that this generates a report name with the appropriate variables for O, R, T, Y, and D, and leaves %I and %N waiting for replacement. Then in the individual sub I tried this:

Expand|Select|Wrap|Line Numbers
  1.     Dim strReportName As String
  2.  
  3.     Call DynamicReportName
  4.  
  5.     strReportName = Replace(strReportName, "%I", "\Internal_")
  6.     strReportName = Replace(strReportName, "%N", "ByInstructor_")
When that didn't work (I got the standard Windows dialog box asking for the file destination/name) I tried outputting "strReportName" to a dialog box to see what I have (I haven't figured out how to use the Immediate window, I only know of its existence), and it's blank. I thought perhaps the problem was that I needed to use one name in the public sub (strOutput) and another in the private sub (strReportName), setting strReportName = strOutput, but that didn't work either.

I'm using Access 2007.

Thanks for any help you can provide! Worst case scenario is I modify 6 times if the drive designations or teams change, but I'm hoping to learn something.
Nov 12 '10 #1
3 1663
NeoPa
32,556 Expert Mod 16PB
Kim,

I like your code. It has style. There are a number of tips I can give to someone in your position. Let me drop a few in :
  1. When you call the DynamicReportName procedure, it is possible, if set up to do so, to pass values to the procedure. You could pass the name of the form you're calling it from, or even just the %I & %N values so the whole job could be done within the procedure.
  2. I see the use of Me. in your procedure code. This is only valid if the procedure code is within a Form Module. Public procedures in Form Modules can only be called from outside their own Form Module if properly qualified.
  3. Multiple references to controls found on Forms!frmMainMenu can be recoded by using the With construct in your code. It's more efficient and easier to read generally. More important the more times it is used of course.
  4. The Choose() function would be a good one to use in line #9 in place of Switch().
    Expand|Select|Wrap|Line Numbers
    1. strReportName = Replace(strReportName, "%R", Choose(Forms!frmMainMenu!optgrpResponsibleTeam = 1, "All", "Education", "Practice", "Research"))

In case it helps, here is a function procedure I use very heavily in my code, that does multiple Replace() calls in a single call. You just pass it as many pairs of parameters as you want :
Expand|Select|Wrap|Line Numbers
  1. 'MultiReplace replaces all occurrences of varParam in strMain with varReplace.
  2. 'Using VbBinaryCompare means that case is not ignored.
  3. Public Function MultiReplace(ByRef strMain As String, _
  4.                              ByVal varParam As Variant, _
  5.                              ByVal varReplace As Variant, _
  6.                              ParamArray avarArgs())
  7.     Dim intIdx As Integer
  8.  
  9.     If (UBound(avarArgs) - LBound(avarArgs)) Mod 2 = 0 Then Stop
  10.     MultiReplace = Replace(Expression:=strMain, _
  11.                            Find:=Nz(varParam, ""), _
  12.                            Replace:=Nz(varReplace, ""), _
  13.                            Compare:=vbBinaryCompare)
  14.     For intIdx = LBound(avarArgs) To UBound(avarArgs) Step 2
  15.         MultiReplace = Replace(Expression:=MultiReplace, _
  16.                                Find:=Nz(avarArgs(intIdx), ""), _
  17.                                Replace:=Nz(avarArgs(intIdx + 1), ""), _
  18.                                Compare:=vbBinaryCompare)
  19.     Next intIdx
  20. End Function
It needs to be included in a standard module in your project.

As for why it's not working, can you answer a few questions :
  1. You seem to have a procedure called DynamicReportName (contents shown in first code group), but the procedure declaration is missing and we have no info as to where (in which module) it is contained.
  2. Without the declaration it's hard to be sure, but the code looks as if it returns the value of strReportName (in which case it's a Function Procedure). That's strange as the call to use it explicitly drops the value it returns. Is this really intentional?
Nov 13 '10 #2
Thanks so much! This is super, just what I was hoping for. I don't have the code at home, but look forward to incorporating your suggestions next week. As to my errors, I expect my attempt at writing a procedure was all wrong, since your explanation makes sense. The drawback to trying to create databases on an as-needed basis using references and posts; I really need to find a VB class, obviously.
Nov 13 '10 #3
NeoPa
32,556 Expert Mod 16PB
My pleasure Kim.

I enjoy helping people who are eager to learn.
Nov 14 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Richard Hollenbeck | last post by:
I have a crosstab query that shows all the scores of all the activities of all the students in all courses, with the students being in the rows and the activities being in the columns and the...
3
by: Climber | last post by:
Hello, I want to now how to do a dynamic report with Crystal Report (C# .Net), the number of colum and row are different each time because they depend of my data base. Thanks Climber
5
by: Anil Gupte | last post by:
How does one access dynamic controls by name (or wahtever other means)? I have the following: Dim newbtnPick As New Button newbtnPick.Name = "SliceButton" & CurSliceNum newbtnPick.Location =...
5
by: Anil Gupte | last post by:
How does one access dynamic controls by name (or whatever other means)? I have the following: Dim newbtnPick As New Button newbtnPick.Name = "SliceButton" & CurSliceNum newbtnPick.Location =...
6
by: Peter Herath | last post by:
I want to create a dynamic report using a crosstab query...... pls someone look into my attached example database and help me out to do the report generation.... example is like dis...: there...
2
by: zoro25 | last post by:
Hi, I want to create a dynamic report and for that I'm using a very simple Combo Box (only one item) and I want to use this filter on my report. Here's the code I came up with: Private Sub...
0
by: rmccorma | last post by:
I have a report which shows the total time spent working by each user on a specified day. I want the text box, which shows the total hours worked on that day, to turn red if a user has not entered...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
4
by: Sep410 | last post by:
Hi all, I have to create a dynamic report in vb.net. I never had done something like this before.Users want to see tables name and when they choose the table they will select which fields should...
2
by: J360 | last post by:
I'm using VB in Access 2003 to generate a dynamic report. I first open the report in design view to set all the grouping levels etc. I then use with rpt .printer.orientation =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.