Run-Time Error '424' - Object Required

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
' ***********
LVL 4
billcuteAsked:
Who is Participating?
 
Leigh PurvisDatabase DeveloperCommented:
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
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Humm ... maybe this line:

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

seems otherwise you would be calling GetModuleFileName recursively ?

mx
0
 
billcuteAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
 
Leigh PurvisDatabase DeveloperCommented:
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
 
Leigh PurvisDatabase DeveloperCommented:
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
 
billcuteAuthor Commented:
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
 
billcuteAuthor Commented:
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
 
Leigh PurvisDatabase DeveloperCommented:
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
 
billcuteAuthor Commented:
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
 
Leigh PurvisDatabase DeveloperCommented:
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
 
billcuteAuthor Commented:
Thanks,
I'll probably try the Vista thread sometime in the nearest future.

Regards
Bill
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.