Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell if MS-Access is active through VB

Status
Not open for further replies.

jasherk

MIS
Jul 24, 2002
5
I'm working on a vb app, that has to call a MS-Access app. I would like to know if there is a way to check and see if the MS-Access app is active or not, so that my program can continue.
vb6, ms-access 2000

Thanks
Jason
 
You could iterate through the running processes to see if you database is open, however, access databases only have an image of 'MSACCESS.EXE'

The way Access locks and keeps track of whos logged in is by creating a temporary file called 'yourdatabase.ldb'

If you open this file you can see what machines have the database open.

You need to get your computername using the API function in kernel32 called GetMachineName()

Then check ldb file by opoening it using binary file functions in VB to see if your machine exists in there.

I can't think of another way but this is fairly simple to do and should be reliable (unless Access crashes in which case the lbd file will not be updated)
 
Jasherk,
Are you looking to see if Access is open on your workstation or is it open on any workstation? If the latter you could try to open it exclusively (this is only possible if the file is not already open) and error will show that the file is in use.

Everybody body is somebodys Nutter.
 
Thanks VBrit,
I think I should explain what I'm doing a little more clearly. Sometimes I take shortcuts, and am not clear.

When the user clicks on the MC button, it should run the access code my "BOSS" wrote"

Set moAccess = New Access.Application
moAccess.OpenCurrentDatabase "C:\! CRM\QS077.mdb", False
moAccess.Visible = True
tmrMCG.Interval = 500
tmrMCG.Enabled = True

This works fine. It loads his application. Now when the user finishes with his app, I need to grab the data he generated. I figured I would just run a timer event checking the status of the moAccess object I launched.

So after enabling the timer event I have the following code in it.

Is_MCG_StillRunning = True
If Not moAccess.CurrentDb.Connection.StillExecuting Then
MsgBox "Get the Data"
Is_MCG_StillRunning = False
End If

I get the following error
run-time error 3251
Operation is not supported for this type of object

I just don't get it.
I hope this helps explain it better.

Jasher
 
Hi Mate,

I just knocked this code up and dumped it on a form.
Create a form with a command button called command1 and change the database path to suit your needs.

This will open the database and you will know when it has closed from the error handler in timer1

Hope this helps.

Martin


Dim o As Access.Application
Dim blnUserOpened As Boolean
Private Sub Command1_Click()
blnUserOpened = True
Set o = New Access.Application
o_OpenCurrentDatabase "C:\Program Files\Altova\XMLSPY2004\Examples\Tutorial\company.mdb"
o.Visible = True
Timer1.Interval = 200
End Sub

Private Sub Timer1_Timer()
On Error GoTo errh
If blnUserOpened Then
DoEvents
'test if user closed, if so this will cause error 2467
If LenB(o.CurrentProject.Name) > 0 Then Exit Sub

End If
exith:

Exit Sub
errh:
If Err.Number = 2467 Then
Set o = Nothing
Timer1.Interval = 0
End If
Resume exith
End Sub
 
Thanks VBrit
Sorry it took so long to respond back. Works great.

Cheers Mate!!!!

Jason
 
It's a pleasure mate! If only they gave me enough work to do at work!

Take care and may the source be with you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top