Controlling the Label Wizard with code

  • Thread starter Thread starter Pete Beatty
  • Start date Start date
P

Pete Beatty

I recently activate the label wizard using code and it works correctly.
However, I noticed that the wizard always stores a copy of the report format
in the report section. The problem is that the default name always assumes
an incremental version of the same report.

For example:
the label wizard is activate pointing to TableA
the default report name is TableA1.........99999

Is there a way to change the report name that the label wizard uses or to
capture the label that the user may enter??
 
Hi, Pete.
Is there a way to change the report name that the label
wizard uses

Try syntax such as the following:

Dim sTblName As String

sTblName = "TableA"

Call acwzmain.frui_entry(sTblName, acReport)
DoCmd.Close acReport, sTblName & "1", acSaveYes
DoCmd.Rename "rptMyReport", acReport, sTblName & "1"

This will work as long as no one manually creates and then saves a report
with the default name ("TableA1"). Otherwise, the default name listed here
would need to be incremented. You should create a function that checks for
the existance of this default name, and if it exists, then it returns a new
default name one higher the highest current increment.
Is there a way to ...
capture the label that the user may enter??

This is the more reliable method if you are distributing the application to
users (i.e., you have no control over what reports are named, other than the
ones you created). You'll have to grab the name after the new report has
been saved. Whenever I've checked, the most recently created object in the
specific Containers Collection has the highest index value. (Caveat:
YMMV.)

Check the count before the new report is created, then after creating the
report, check the count again. If the count is one higher than before
(i.e., the user saved the report instead of canceling the process), then get
the name of the report from the last index value in the Reports Container
Collection. (Remember that the first item in this container is at index =
0, so don't use the Container's Count property as the index value for
retrieving the name.) For the count, try syntax such as the following:

numRpts = CurrentDb().Containers("Reports").Documents.Count

To get the name of the newest report, try the following syntax:

sRptName = CurrentDb().Containers("Reports").Documents(numRpts - 1).Name

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
 
Hi, Pete.

Now that I reread your post, I realize that I may have misread your
questions. I'm not quite sure if you want to rename the report that the
Wizard creates for you or you merely want to change the report's "Title"
displayed on a label in the report's header, and leave the report's name the
same.

As you know, the name on this label is taken from the report's name (which
the code I gave on my previous reply shows how to change). You won't be
able to change the label's caption until after the Report Wizard is finished
saving the report. Is this what you want to change?

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
 
Hi, Pete.

Well, I don't see any reply to my question, but I've got some sample code
that will change the caption of the label for the report's title after the
Report Wizard creates the new report, so even if you don't need it, I'll
post it anyway. There's a guy in Canada who's been waiting all day to see
the code. ;-)

' ***** Start of code *****

'==================================================
' This procedure requires the acwzmain.MDE library reference.
' ASSUMPTIONS:
' 1. A report named "TableA" has already been saved.
' 2. No report named "TableA1" has yet been saved.
'==================================================

Public Sub createReport( )

On Error GoTo ErrHandler

Dim rpt As Report
Dim ctrl As Control
Dim sTblName As String
Dim idx As Long

sTblName = "TableA"

Call acwzmain.frui_entry(sTblName, acReport)
DoCmd.Close acReport, sTblName & "1", acSaveYes
DoCmd.Rename "rptMyReport", acReport, sTblName & "1"

DoCmd.OpenReport "rptMyReport", acViewDesign
Set rpt = Reports("rptMyReport")

For Each ctrl In rpt.Section(acHeader).Controls
'-------------------------------------------
' Find 1st label & replace the caption.
'-------------------------------------------

If (ctrl.ControlType = acLabel) Then
rpt.Section(acHeader).Controls(ctrl.Name).Caption = "MyTitle"
Exit For ' Stop looking.
End If
Next ctrl

DoCmd.Close acReport, rpt.Name, acSaveYes

CleanUp:

Set ctrl = Nothing
Set rpt = Nothing

Exit Sub

ErrHandler:

MsgBox "Error in createReport( ) in RptFunctions." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
GoTo CleanUp

End Sub ' createReport( )

' ***** End of code *****

The same caveats I mentioned in my first post still apply.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
 
Back
Top