[AccessD] Cannot create multiple Dynamic Reports (NEEDED BEFORE 16:00 CET)

Bob Hall rjhjr at cox.net
Fri Aug 15 11:09:56 CDT 2003


On Fri, Aug 15, 2003 at 12:27:26AM -0700, Sad Der wrote:
> Hi group,
> 
> I'm getting desperate. I need to finish a project at
> 16:00 cet because my plane flies at 18:00 AAAHHRG.
> I've created a function that creates a report. Of
> course now the users needs more reports. It can vary
> from 2-17(!)
> I keep getting the error:
> 2147
> You must be in design view to create or delete
> controls.
> 
> The error is correct because the line:
> Set rpt = CreateReport 
> Creates a new report called "Report1" As you can see I
> tried giving the new report a name (using an extra
> param) but I could not get it to work. 
> 
> I also added the line:
> '    DoCmd.OpenReport strReportName, acViewDesign

I don't know if I'm posting this soon enough to do you any 
good, but I've done this by making a copy of the report, and 
apply the new name to the copy. In order to make a copy with a 
new name, you need the name of the original. Here's one way of 
getting the name. Someone else may have a simpler technique, 
but this has worked reliably in an app I created about 18 
months ago.

Name the original report by closing it, and opening the report listed 
in the MSysObjects table that was created in the last 4 seconds. Here's 
a code sample. Sorry about the language, but the important parts are in 
English. Use 
	Save:=acSaveYes
instead of
	Save:=acSavePrompt
if you don't want the user to name the report. 

    If BarnTilForelderRptOppretta Then
        'Om koden lyktes med å opprette rapporten, så lukk den. Koden ber om et nytt navn,
        'og bruker navnet som brukeren skaffer. Deretter vet Hamsteren ikke navnet.
        DoCmd.Close ObjectType:=acReport, ObjectName:=RptNavn, Save:=acSavePrompt
        'Finn navnet til den nye rapporten. Den skal være rapporten som skaptes innen de
        'siste fire sekundene.
        Set db = CurrentDb
        strSQL = "SELECT [Name] FROM MSysObjects" _
                & " WHERE DateDiff('s', [DateCreate], Now()) < 4" _
                    & " AND Left$([Name], 4) <> '~sq_'" _
                & " ORDER BY [DateCreate] Desc;"
        Set rs = db.OpenRecordset(name:=strSQL, Type:=dbOpenForwardOnly)
        With rs
            If Not (.BOF And .EOF) Then
                'Nå vet Hamsteren navnet.
                RptNavn = ![name]
                DoCmd.OpenReport ReportName:=RptNavn, View:=acViewDesign


Bob Hall


More information about the AccessD mailing list