Opening report, on DB open

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Opening report, on DB open

Post by Egg 'n' Bacon »

Not sure how best to doe this; I want a report (showing overdues) to display on opening the DB. Though if there is no data for the form, then a simple message box will be displayed instead. I have set the menu form to open this, but it ends up in the background, with the form having the focus.

Here's what I have so far;

Code: Select all

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

    DoCmd.OpenReport "rptOdueTesting", acViewPreview
Exit_Form_Open:
    Exit Sub
    
Err_Form_Open:
    If Err = 2501 Then
    MsgBox trMsgNoDataForReport, vbInformation, "No overdues"

    Else
    ' Display error message
    MsgBox Err.Description, vbExclamation
End If
End Sub
Is there a better way of doing this?

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Re: Opening report, on DB open

Post by Egg 'n' Bacon »

Oh just remembered, is there any way of restricting this to ONLY when the DB opens?

User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening report, on DB open

Post by HansV »

You could create a function in a standard module that opens the report/displays the message, and call this function (using the RunCode action) from a macro named AutoExec. An AutoExec macro will be run automatically when the database is opened.
Best wishes,
Hans

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Re: Opening report, on DB open

Post by Egg 'n' Bacon »

OK now this is something I've not done before, but I did give it a go and was (mostly) successful :)

Only trouble is, due to the company security requirements I'm now getting an "action failed" (error 2950) message. The user has to "Enable this content" prior to the rest of the DB opening (and thereby the report).

Is it possible to avoid this?

User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening report, on DB open

Post by HansV »

You're using Access 2007, isn't it? Users should add the folder containing the database to their Trusted Locations. See Create, remove, or change a trusted location for your files. (This can probably be done with a group policy too, but I can't help you with that)
Best wishes,
Hans

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Re: Opening report, on DB open

Post by Egg 'n' Bacon »

OK, that's the problem.

I'll have to twist our IT guy's arm to sort this one out then :)

Cheers Hans