Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Posts
    13

    Unanswered: How to use API's with VBA

    Hi, I want to now the name of the computer with my Access program. I found this code, but it doesn't work properly. Does anybody know how to use API's with VBA in Access.

    I'll put the code:

    IN THE MODULE:
    Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, _
    nSize As Long) As Long
    Public Function Computer() As String
    Dim Name As String * 255, Answer As Long, Length as Long, Res As Long

    'Create Buffer
    Name = ""
    Length = Len(Name)
    Res = GetComputerName(Name, Length)
    If Res and Length > 0 Then
    Computer = Left$(Name, Length)
    Else
    Computer = "Doesn't found"
    End If
    End Function

    IN THE FORM:
    Private Sub Form_Load()
    MsgBox Computer
    End Sub

    Thanks for the help!

  2. #2
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346

    Re: How to use API's with VBA

    Try using a length that is bigger then 0. The API call trys to put the name into a zero length variable and that is where you may have a problem.

    i.e.

    Length = 10
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •