|
-
Oct 20th, 2005, 03:32 PM
#1
Thread Starter
Fanatic Member
Determine if instance of access is open
Hi, all is there a way to determine if my access object is open? (meaning the database is open via my object) Here is my code:
VB Code:
Sub Main
Dim acc As New Access.Application
acc.OpenCurrentDatabase
'How do I determing if acc is open? In the example above I
'know its open, but there are cases in my program when I don't know if its been opened or not.
End Sub
I was thinking there should be something similiar to the ADO connection object (cn.state) but it wasn't. And (if acc is Nothing) doesn't determine if its open.
Thanks,
Strick
-
Oct 20th, 2005, 04:04 PM
#2
Fanatic Member
Re: Determine if instance of access is open
I would recommend just setting a boolean property called IsOpen. Set it to True when you open Access and False when you close it.
Are you writing in Access or VB.NET? If VB.NET why use the Access.Application? Also, instantiating Access like that can come back to bite you if you have different versions of Access around.
-
Oct 20th, 2005, 05:11 PM
#3
Re: Determine if instance of access is open
This is what I use for Access to attach to a running instance. Then f its not running I can create a new instance.
VB Code:
Friend moApp As Access.Application
Private mbKillMe As Boolean
Friend Property KillMe() As Boolean
Get
KillMe = mbKillMe
End Get
Set(ByVal Value As Boolean)
mbKillMe = Value
End Set
End Property
Friend Sub InitializeMe()
Try
'<INITIALIZE ACCESS>
moApp = DirectCast(GetObject(, "Access.Application"), Access.Application)
Catch ex As Exception
'Access not running. Create a new instance or not. Up to you.
If TypeName(moApp) = "Nothing" Then
moApp = DirectCast(CreateObject("Access.Application"), Access.Application)
mbKillMe = True
Else
MessageBox.Show(ex.Message, "VB/Office Guru™", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Try
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'<CALL THE SPELLME INITIALIZATION PROCEDURE BEFORE ANY USE>
InitializeMe()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If KillMe = True Then
moApp.Quit(False)
End If
moApp = Nothing
End Sub
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|