Close report code not working (1 Viewer)

jd_boss_hogg

Registered User.
Local time
Today, 04:17
Joined
Aug 5, 2009
Messages
88
Hi All - i'm a newby to VBA, so please be gentle on me ...:)

The following code crashes the database at this line in both situations:-
DoCmd.Close acReport, "Month_rp", acSaveNo

i'm trying to close the report." It's a very very basic password check, and the code is assigned to 'on open' of the form.

Code:
Private Sub Report_Open(Cancel As Integer)
     Dim strPasswd

    strPasswd = InputBox("Enter Password", "Restricted Form")

    'Check to see if there is any entry made to input box, or if
    'cancel button is pressed. If no entry made then exit sub.

    If strPasswd = "" Or strPasswd = Empty Then
        MsgBox "No Input Provided", vbInformation, "Required Data"
        DoCmd.Close acReport, "Month_rp", acSaveNo
        Exit Sub
    End If

    'If correct password is entered open Employees form
    'If incorrect password entered give message and exit sub

    If strPasswd = "fred" Then
       
    MsgBox "Password Correct!"
    
  Else
        MsgBox "Sorry, you do not have access to this report", _
               vbOKOnly, "Important Information"
        
        DoCmd.Close acReport, "Month_rp", acSaveNo
        Exit Sub
    End If
    
End Sub
Any ideas why it actually crashes the whole dbase?

thanks !
 

ajetrumpet

Banned
Local time
Yesterday, 21:17
Joined
Jun 22, 2007
Messages
5,638
could it be that you're trying to close the form on the OPEN event? it's trying to do two things at once, possibe that it?
 

jd_boss_hogg

Registered User.
Local time
Today, 04:17
Joined
Aug 5, 2009
Messages
88
I don't think so, because i use exactly the same coding on a couple of other forms (so DoCmd AcClose AcForm) instead of Acreport. It's just the report one that crashes?

I'll give it a go anyway..
 

Users who are viewing this thread

Top Bottom