Closing a report from within a form

Smart

Registered User.
Local time
Today, 00:07
Joined
Jun 6, 2005
Messages
436
I currently have a form with a combo box that shows all employees
When I select an employee a report is run in preview mode (after update of combox)
If I then select another employee from the combo box I want to close the previous report preview and open the report for the newly selected employee

I have tried docmd.close acreport,"reportname" but it errors with
2493 action requires an object name argument.

There must be a way to do this hope fully some body out there can help

Cheers
 
I have attached asample of the database
It opens with a form
select name from combo box and the error occurs
 

Attachments

that was it !!!!

Dear smart,

Your problem is that you left stDocname empty !!!!

here is the code.


Private Sub scrStudent_AfterUpdate()
On Error GoTo Err_AftUpdate
Dim stDocName As String
Dim absencelogged As String

absencelogged = Nz(DLookup("[Name]", "[Qry_Preview_Current_Absence]"), "")


If absencelogged = "" Then
MsgBox "No Absences Have Been Logged For This Employee", vbInformation, "No Absence Logged"
Else
' the problem is here, at the first time you select a name it will give a error
'because stDocName is empty.
'-----------------------------------------------------
stDocName = "Rep_Preview_Current_Absence"
'-----------------------------------------------------
DoCmd.Close acReport, stDocName
stDocName = "Rep_Preview_Current_Absence"
DoCmd.OpenReport stDocName, acPreview
End If

Exit_AftUpdate:
Exit Sub

Err_AftUpdate:


If Err.Number = 2492 Then

Resume Exit_AftUpdate
Else
MsgBox Err.Number & vbCrLf & Err.Description
Resume Exit_AftUpdate
End If
End Sub
 
thanks

Thanks for the reply

I spotted the error must have been having a blonde moment
 

Users who are viewing this thread

Back
Top Bottom