Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 09-20-2009, 01:40 AM   #1
jd_boss_hogg
Newly Registered User
 
Join Date: Aug 2009
Location: france
Posts: 84
Thanks: 1
Thanked 1 Time in 1 Post
jd_boss_hogg is on a distinguished road
Send a message via Skype™ to jd_boss_hogg
Close report code not working

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 !

jd_boss_hogg is offline   Reply With Quote
Old 09-20-2009, 01:44 AM   #2
ajetrumpet
Banned
 
Join Date: Jun 2007
Location: Universe - Local Group - Milky Way Galaxy - Orion Arm
Posts: 5,640
Thanks: 0
Thanked 100 Times in 47 Posts
ajetrumpet has a spectacular aura about ajetrumpet has a spectacular aura about
Send a message via MSN to ajetrumpet Send a message via Yahoo to ajetrumpet
Re: Close report code not working

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?
ajetrumpet is offline   Reply With Quote
Old 09-20-2009, 11:22 PM   #3
jd_boss_hogg
Newly Registered User
 
Join Date: Aug 2009
Location: france
Posts: 84
Thanks: 1
Thanked 1 Time in 1 Post
jd_boss_hogg is on a distinguished road
Send a message via Skype™ to jd_boss_hogg
Re: Close report code not working

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..

jd_boss_hogg is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to open and close Excel not working cpremo Macros 8 10-23-2008 08:26 PM
Help with VBA code that was working but now is not sammylou Modules & VBA 4 10-09-2007 03:31 AM
multi calcs for report: best to use query or in code of report? chard2 General 3 04-17-2005 02:04 AM
Close Report, Open Form mrabrams2 Reports 4 05-28-2004 11:52 AM
Can't close form with code chuckgoss Forms 1 05-15-2001 01:29 PM




All times are GMT -8. The time now is 02:53 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World