Hi Guys
I write down the following code within Access module to get computer name and username . So for every new Access database I will need to write down the same code to retrieve computer name and user name.
As we have now moved on to sql server so we are using Access frontend and sql server backend. At the moment sql server stores only the tables and all the procedures/functions/queries etc resides in Access frontend.
So I am thinking of a way to use stored procedures in sql server to store code to get computer name and user name . How the below piece of code can be written as stored procedures within sql server:
Any help will be much appreciated. Thanks
I write down the following code within Access module to get computer name and username . So for every new Access database I will need to write down the same code to retrieve computer name and user name.
As we have now moved on to sql server so we are using Access frontend and sql server backend. At the moment sql server stores only the tables and all the procedures/functions/queries etc resides in Access frontend.
So I am thinking of a way to use stored procedures in sql server to store code to get computer name and user name . How the below piece of code can be written as stored procedures within sql server:
Code:
Option Compare Database
Option Explicit
Public Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long
Public Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long
Public Function NameOfComputer()
' Returns the name of the computer
Dim ComputerName As String
Dim ComputerNameLen As Long
Dim Result As Long
ComputerNameLen = 256
ComputerName = Space(ComputerNameLen)
Result = GetComputerName(ComputerName, ComputerNameLen)
If Result <> 0 Then
NameOfComputer = Left(ComputerName, ComputerNameLen)
Else
NameOfComputer = "Unknown"
End If
End Function
Function NameofUser() As String
' Returns the name of the logged-in user
Dim Buffer As String * 100
Dim BuffLen As Long
BuffLen = 100
GetUserName Buffer, BuffLen
NameofUser = Left(Buffer, BuffLen - 1)
End Function
Any help will be much appreciated. Thanks