MS Access VBA, all my Api calls return EMPTY

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rpie
    New Member
    • Apr 2008
    • 5

    MS Access VBA, all my Api calls return EMPTY

    I am using Access 2003 and no single Api call will work??
    All my Api calls return EMPTY .

    Some examples I tried:
    Code:
    Declare Function apiGetVersion Lib "kernel32" Alias "GetVersion" () As Long
    
    Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Declare Function api_GetUserName Lib "c:\windows\system32\advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal hostname As String) As Long
    
    Private Declare Function inet_addr Lib "WSOCK32.DLL" (ByVal s As String) As Long
    When calling no errors occur but the return value is always zero.
    I use MS Access 2003 and my computer(s) run Windows XP Pro (SP2).

    The last time I needed to use Api calls was with Access 8 and Windows 95, can’t remember that is was such a struggle.

    I really hope someone can help me with this.

    Thanks,
    Raymond
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hi, Raymond.

    Did you check error code?
    If not, then get it with Err.LastDllErro r property and refer to System Error Codes.

    Regards,
    Fish

    Comment

    • rpie
      New Member
      • Apr 2008
      • 5

      #3
      Hi Fish,

      Thank you for your fast reply.
      The strange thing is that I don't get any error.
      For example if I use this code:
      Code:
      Private Declare Function GetComputerName Lib "Kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
      
      Public Function GetPcName() As String
          Dim strBuf As String * 16, strPcName As String, lngPc As Long
          lngPc = GetComputerName(strBuf, Len(strBuf))
          If lngPc <> 0 Then
              strPcName = Left(strBuf, InStr(strBuf, vbNullChar) - 1)
              GetPcName = strPcName
          Else
              GetPcName = vbNullString
          End If
      End Function
      No errors occur and err.LastDllErro r=0 all the time.
      lngPc will return 0 after calling GetComputerName .
      This happens with all my Api calls, no errors but also nothing happens.

      :( Raymond

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        Hi, Raymond.

        The code runs fine. The only idea I have is that you may have missing references to external libraries. Have you checked this?

        Comment

        • rpie
          New Member
          • Apr 2008
          • 5

          #5
          Originally posted by FishVal
          Hi, Raymond.

          The code runs fine. The only idea I have is that you may have missing references to external libraries. Have you checked this?
          I use the following Libraries:
          Visual Basic For Applications
          Microsoft Access 11.0 Object Library
          Microsoft DAO 3.6 Object Library
          Microsoft ActiveX Data Objects 2.5 Library
          Microsoft Visual Basic for Application Extensibility 5.3
          Microsoft Windows Common Controls 6.0
          Microsoft Forms 2.0 Object Library

          Do I miss something or is this not what you mean?

          Comment

          • rpie
            New Member
            • Apr 2008
            • 5

            #6
            Hi Fish,

            I re-installed Windows XP and MsAccess 2003 on new computer and now everything works fine.

            Don't now what happened to my other systems.

            Thanks for the time you spent helping me,
            Raymond

            Comment

            • FishVal
              Recognized Expert Specialist
              • Jun 2007
              • 2656

              #7
              You are welcome.
              Good luck.

              Comment

              • rpie
                New Member
                • Apr 2008
                • 5

                #8
                Apparently the anti virus software from Kaspersky seems to be problem

                Always the Russians! ;)

                Raymond

                Comment

                • FishVal
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2656

                  #9
                  They are everywhere. ;)

                  Comment

                  Working...