?
Solved

Run-Time Error '424' - Object Required

Posted on 2007-10-21
12
Medium Priority
?
1,082 Views
Last Modified: 2013-11-28
Is there any idea of resolving the Run_Time Error '424' ?....coming from the "
"Public Function IsDevEnv() As Boolean" ....from my code below:

At best if there is a solution based error trapping with a msgbox:
... informing user that his entry in the text field is invalid and to re-enter it...etc..just an idea.

The error results from a user wrongly input in a "text" field...

...after which the Run-Time Error '424' is displayed. .........In debug mode...simply placing a mouse over the error line code displays....

lngCount = 0
' ***********

Run-Time error '424':
"Object required"

....on this line.....

lngCount = GetModuleFileName(App.hInstance, strFileName, 255&)

.....from my Function below:

' ..............declaration.............................
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As Long
' .......................................................
Public Function IsDevEnv() As Boolean

    Dim strFileName$
    Dim lngCount&
   
    strFileName = String(255, 0)
    lngCount = GetModuleFileName(App.hInstance, strFileName, 255&)          ' <<<=== Error Line
    strFileName = left(strFileName, lngCount)
   
    IsDevEnv = (UCase(right(strFileName, 7)) Like "VB?.EXE")

End Function
' ***********
0
Comment
Question by:billcute
  • 5
  • 5
  • 2
12 Comments
 
LVL 75
ID: 20118621
Humm ... maybe this line:

lngCount = GetModuleFileNameA(App.hInstance, strFileName, 255&)      ' ** add the A

seems otherwise you would be calling GetModuleFileName recursively ?

mx
0
 
LVL 4

Author Comment

by:billcute
ID: 20119494
MX,
When I added A I received an error upon testing that "Sub" or "Function" not defined.

...on
lngCount = GetModuleFileNameA (App.hInstance, strFileName, 255&)
                                                ~~~
0
 
LVL 75
ID: 20120183
Bill ... Sorry ... ignore my last post ... I misread the code ...

There must be something wrong with:

App.hInstance

where is that defined 'App'

mx
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 20120528
App is a Visual Basic object (it's approximate equivalent of Access' Application object).
I'm assuming that Bill has copied the code from such a VB5/6 offering?

However Access has no equivalent to hInstance.
You could look to acquire such a value from another API call.

Declare Function GetModuleHandle& Lib "kernel32" Alias "GetModuleHandleA" (ByVal FileName$)
Declare Function GetModuleFileName& Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule&, ByVal FileName$, ByVal nSize&)

Public Function IsDevEnv() As Boolean

    Dim strFileName$
    Dim lngCount&
    Dim intInst&
   
    intInst& = GetModuleHandle("MSACCESS.EXE")
    strFileName = String(255, 0)
    lngCount = GetModuleFileName(intInst&, strFileName, 255&)          ' <<<=== Error Line
    strFileName = Left(strFileName, lngCount)
   
    IsDevEnv = (UCase(Right(strFileName, 7)) Like "VB?.EXE")

End Function

The general goal makes little sense to me though...
What's the intended purpose of the code?
The implementation above is entirely geared around VB.
It's checking whether the application is currently being developed (i.e. if the running code is executed from an application named VB?.EXE... as opposed to MyApp.exe or whatever the eventual app would be).

The closest equivalent in Access would probably be to test if an application is an MDE or MDB.  (Which as well all know isn't the same).
You can determine if the applicaiton is an MDE by checking for the appropriate property of the application (the property holds the value "T" is it has been so set).


Function fIsMDE(Optional strFile As String) As Boolean
On Error Resume Next

    Dim db As Database
    Dim strProp As String
   
    If len(strFile) > 0 Then
        Set db = DBEngine.OpenDatabase(strFile)
    Else
        Set db = CurrentDb
    End If

    strProp = db.Properties("MDE")
    If strProp = "T" Then
        fIsMDE = True
    End If
   
    db.Close
    Set db = Nothing
   
End Function
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 20120589
Just thought - before heading off for a few hours - you might mean you're wanting to determine if you're running in Runtime mode?
That can be just:

Function fIsRuntime() As Boolean

    fIsRuntime = SysCmd(acSysCmdRuntime)

End Function
0
 
LVL 4

Author Comment

by:billcute
ID: 20121866
LPurvis:
I tried the code posted in your first comment I received Run-Time Error '70': "permission denied.
Yes, as you've rightly guessed, I am working of Ms. Access 2003 not VB. The code I got from MSDN forum for resolving problems surrounding the SENDKEYS associated with Ms. Office Application and Windows Operating Systems - including Windows Vista.
______________________
Here is the complete code:
Option Compare Database
Option Explicit

'OsVersion and IsDevEnv and updated Sendkeys replacement

'get os version
Private Type OSVERSIONINFO
  dwOSVersionInfoSize As Long
  dwMajorVersion As Long
  dwMinorVersion As Long
  dwBuildNumber As Long
  dwPlatformId As Long
  szCSDVersion As String * 128
End Type

Private Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As Long
'*******
Public Function OsVersion() As Single
    Dim os As OSVERSIONINFO
    Dim retval As Long
    os.dwOSVersionInfoSize = Len(os)
    retval = GetVersionEx(os)  ' read Windows's version information
'    MsgBox "Windows version number:" & os.dwMajorVersion & Chr(Asc(".")) & os.dwMinorVersion
'    MsgBox "OS Version Info Size = " & os.dwOSVersionInfoSize
'    MsgBox "BuildNumber = " & os.dwBuildNumber
'    MsgBox "Platform ID = " & os.dwPlatformId 'Note If ID =0 win 3.x , ID=1 win9x and ID =2 WINNT
'    MsgBox "CSD Version = " & os.szCSDVersion
   
    OsVersion = Val(os.dwMajorVersion & "." & os.dwMinorVersion)
   
End Function
' *********
Public Function IsDevEnv() As Boolean
    Dim strFileName$
    Dim lngCount&
    Dim intInst&
    intInst& = GetModuleHandle("MSACCESS.EXE")
    strFileName = String(255, 0)
    lngCount = GetModuleFileName(intInst&, strFileName, 255&)          ' <<<=== Error Line
    strFileName = left(strFileName, lngCount)
    IsDevEnv = (UCase(right(strFileName, 7)) Like "VB?.EXE")
End Function
'******
    'replace code in my first post with this, the previous code failed to send a key on the first call
Public Function Sendkeys(Text$, Optional wait As Boolean = False)

        Static init As Boolean, IsIDEUnderVista As Boolean, WshShell As Object
   
        'wrapper for Sendkeys which does not cause an Error 70 in the IDE under Windows Vista
        'WshShell does not get set to Nothing before App ends but any problems related to that only happen in the IDE
        'Errors due to WScript disablement on the OS can only happen under the IDE
        'Extra overhead for the WshShell object is only required under the IDE

        If Not init Then
            If IsDevEnv() Then
                IsIDEUnderVista = (OsVersion() >= 6)
                    If IsIDEUnderVista Then Set WshShell = CreateObject("WScript.Shell")
                End If
            init = True
        End If
   
        If Not IsIDEUnderVista Then
            VBA.Sendkeys Text$, wait
   Else
            WshShell.Sendkeys Text$, wait
        End If
    Exit Function
End Function
' ************

If you assist in converting the above to work with Ms. Access 2003 - it would be great.
0
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 2000 total points
ID: 20122229
The usual "replacement" for SendKeys in VBA is at http://www.mvps.org/access/api/api0046.htm.

What you're doing here - are you wanting to check for Vista to launch a Scripting alternative Sendkeys?
0
 
LVL 4

Author Comment

by:billcute
ID: 20128584
LPurvis,
Thanks for Link. What is the call for the Functions. I tried
mySendKeys sKeys, bWait

I received a compile error:
ByRef argument type mismatch

on....
sKeys


In my code....here is how the sendkeys was used..

' ........................................
'.........................................
 If BldgDisttxtNewValue = "" Then
        msgbox sError, vbInformation + vbOKOnly, "Invalid Value, press ESC twice to retry"
        Sendkeys Chr(27) & Chr(27)     '<<--- error this line
 '       Me!BldgDisttxt.Undo
        Cancel = True
       End If
End Sub
Regards
Bill
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 20129250
You call mySendKeys exactly as you would Sendkeys.
So if you were calling (for whatever reason)
Sendkeys Chr(27) & Chr(27)
then you'd use
mySendKeys Chr(27) & Chr(27)

as bWait is just an optional argument.
Of course - the whole use of Sendkeys at all - comes with the inevitable caveat that it's potentially unreliable.
However if SendKeys has some other issue under Vista - and hence the Scripting option is better then some of the above code might need to be implemented.  (I can't imagine it's particularly safer though).
0
 
LVL 4

Author Comment

by:billcute
ID: 20129559
LPurvis,
I tried .. mySendKeys Chr(27) & Chr(27)
and I received a Run-time error '70':  "permission denied"...

I couldnt figure out how to use the bwait option...anyway it could be a Vista problem.

Thanks for assisting.

Regards
Bill
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 20130022
Then this would indeed seem to be a Vista issue thread (which is what I was wondering).

You'd then go back to your replacement function for Sendkeys (named Sendkeys :-s).
I don't see why you need to worry about the Dev environment...
It could be just...

Public Function Sendkeys(Text$, Optional wait As Boolean = False)

        Static init As Boolean, IsIDEUnderVista As Boolean, WshShell As Object

        If Not init Then
            IsIDEUnderVista = (OsVersion() >= 6)
            If IsIDEUnderVista Then Set WshShell = CreateObject("WScript.Shell")
            init = True
        End If
   
        If Not IsIDEUnderVista Then
            VBA.Sendkeys Text$, wait
        Else
            WshShell.Sendkeys Text$, wait
        End If

End Function


or if you weren't concerned about performance - then perhaps


Public Function Sendkeys(Text$, Optional wait As Boolean = False)

        Dim IsIDEUnderVista As Boolean, WshShell As Object

        IsIDEUnderVista = (OsVersion() >= 6)
        If IsIDEUnderVista Then Set WshShell = CreateObject("WScript.Shell")
   
        If Not IsIDEUnderVista Then
            VBA.Sendkeys Text$, wait
        Else
            WshShell.Sendkeys Text$, wait
        End If

End Function
0
 
LVL 4

Author Comment

by:billcute
ID: 20135740
Thanks,
I'll probably try the Vista thread sometime in the nearest future.

Regards
Bill
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question