Results 1 to 4 of 4

Thread: Macro Help

  1. #1

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Macro Help

    I would like to create a macro in access which closes the database when a report is closed. Can anyone advise how i would go about doing this?

    The reason behind this is that in my vb.net app i have a function to view access reports however once the report has been closed i dont want the user to be able to access anything else in the database therefore i will run the macro from my app to close the database.

    Would appreciate any help greatly

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Macro Help

    You can probably add VBA code to the class behind the report to do that but it may be better to use your vb.net automation code to execute the .Quit method of the Application (Access) object.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Re: Macro Help

    Ok thanks. Heres my code for viewing a report:

    Code:
             Try
    
                Dim oAccess As Access.Application
    
                oAccess = New Access.Application
    
                oAccess.Visible = True
    
                Call oAccess.OpenCurrentDatabase(filepath:=FilePath, Exclusive:=False, bstrPassword:="A5B7C5D8E4")
    
                With oAccess.DoCmd
    
                    .OpenReport(ReportName:=ReportName, View:=Access.AcView.acViewPreview)
    
                    .Maximize()
    
                End With
    
                oAccess = Nothing
    
            Catch ex As Exception
    
                MessageBox.Show("The following error occured: " & ex.Message)
    
            End Try
    How would i go about detecting when the report has closed in access so that i can call oAcces.Quit?

  4. #4

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Re: Macro Help

    Can anyone help with this? Last thing i need to complete application

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width