Results 1 to 8 of 8
  1. #1
    jsbotts is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Aug 2011
    Location
    Hobbs, NM
    Posts
    14

    VBA - Using GetObject function - get error.

    I have an MS Access application and it opens a file from MS Word. Before I close the MS Access form, I need to programmatically determine if the MS Word application is running. I use the following sub and function:



    Code:
    Private Sub cmdbCloseCC_Click()
    On Error GoTo PROC_ERR
        Dim wn As String
        wn = "Word.Application"
        If Me.IsAppRunning(wn) = True Then
            wo.Quit
            Set wo = Nothing
        End If
        
        DoCmd.Close acForm, "frmCC_Status"
        Application.Quit
    PROC_EXIT:
        Exit Sub
    PROC_ERR:
        MsgBox Err.Description
        Resume PROC_EXIT
    End Sub
    ___________________________________________
    Function IsAppRunning(ByVal appName) As Boolean
        Dim oApp As Object
        On Error Resume Next
        
        Set oApp = GetObject(, appName)    'Error here - Run-time error '429': 
        'ActiveX component can't create object
        Debug.Print oApp
        If Not oApp Is Nothing Then 
            Set oApp = Nothing
            IsAppRunning = True
        End If
    End Function

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    if you have an error handler already and you still get an error and it stops executing, turn the option off in 'options'.

    doesn't the error mean that word is closed? sounds like it. what else could it be?

  3. #3
    jsbotts is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Aug 2011
    Location
    Hobbs, NM
    Posts
    14
    Adam,
    When I run IsAppRunning I always get a return of True, no matter if there is an instance of Word or not.
    jsbotts

  4. #4
    stmoong is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    The run-time error simply means that no instance is running, i.e. Word is not running. Trying adding an else condition to return false from the function.

  5. #5
    jsbotts is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Aug 2011
    Location
    Hobbs, NM
    Posts
    14
    Stan,
    I have tried that and it makes no difference. I still get a return of true whether a Word instance is present or not.

  6. #6
    goodguy is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Location
    Zanzibar, Tanzania
    Posts
    229
    Break at line 26 and test the value of oApp. Your code is testing for Nothing, what about other Null values?

  7. #7
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by jsbotts View Post
    Stan,
    I have tried that and it makes no difference. I still get a return of true whether a Word instance is present or not.
    it looks like your code is running just fine.

    What it looks like you're discovering is one of two things here:

    1) a dimmed "object" does not start out as NOTHING, or
    2) the error is turning the "object" from NOTHING to something else

    you should be able to solve this by putting an error handling section in this and setting the return to TRUE in it, but setting the return to FALSE before it and exiting the function. If it errors when there is not an instance of word running, that should be the way it is done anyway! e.g. - using an error to determine the return you get. What's in your way right now is the fact that you're not using 'GOTO' when you encounter the error. Fix that and you'll be fine.

  8. #8
    stmoong is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    Try something like this.

    Code:
    Function IsAppRunning(ByVal appName) As Boolean
        Dim oApp As Object
        On Error Goto ERR_HANDLER
         
        Set oApp = GetObject(, appName)    'Error here - Run-time error '429': 
        'ActiveX component can't create object
        Debug.Print oApp
        If Not oApp Is Nothing Then
            Set oApp = Nothing
            IsAppRunning = True
        Else
            IsAppRunning = False
        End If
    
        Exit Function
    
    ERR_HANDLER:
        Set oApp = Nothing
        If Err.Number = 429 Then
            IsAppRunning = False
        Else
            ' Handle other errors
        End If
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. aggregate error due to function
    By boutwater in forum Access
    Replies: 2
    Last Post: 09-26-2011, 03:39 PM
  2. Compile error: code or function not defined
    By GeorgeBrown in forum Access
    Replies: 1
    Last Post: 09-19-2011, 10:25 AM
  3. Silly error on a simple function call - help
    By allenjasonbrown@gmail.com in forum Programming
    Replies: 5
    Last Post: 06-10-2011, 01:23 PM
  4. Compile error. Sub of function not defined
    By plavookins in forum Reports
    Replies: 7
    Last Post: 04-22-2011, 10:15 AM
  5. an aggregate function error message
    By newtoAccess in forum Queries
    Replies: 1
    Last Post: 11-27-2010, 05:18 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums