Auto Capture IP address into Field

BrianE

Registered User.
Local time
Today, 01:47
Joined
Mar 6, 2008
Messages
10
Hi,

I am nearing the endgame of a FE/BE app. The FE will sit on various PC's across a LAN. IS there a way that when a user opens a record (via a form) on his FE (on his PC), the IP addy of that PC will be automatically entered into a hidden field on the form and store it in a purpose specific field on the BE table.

So I guess my question is how do I get the IP into a field on a table? Either "default" in the table, or via a field on a form? And what would the syntax for such an auto-populate be?

Thanks
Brian
Pretoria
South Africa
 
Hi,

I am nearing the endgame of a FE/BE app. The FE will sit on various PC's across a LAN. IS there a way that when a user opens a record (via a form) on his FE (on his PC), the IP addy of that PC will be automatically entered into a hidden field on the form and store it in a purpose specific field on the BE table.

So I guess my question is how do I get the IP into a field on a table? Either "default" in the table, or via a field on a form? And what would the syntax for such an auto-populate be?

Thanks
Brian
Pretoria
South Africa

I did a google search and found material here:
http://www.everythingaccess.com/tutorials.asp?ID=Get-all-IP-Addresses-of-your-machine

I did a copy and paste under Access2003 and it worked fine for me.

Perhaps you can adapt it to your needs.

Good luck.
 
Thanks, that is useful, now I must just figure out how to parse the output from that module to get the one I want to be logged. :)

I get:

41.213.60.125
127.0.0.1
192.168.250.1

I want to save the 192.168.250.1 into a field called IP on each record in a table. I suppose I need to set each IP address as a global variable? How would I do that, I am not that sharp in VBA....

This module has helped a lot in getting there.

Brian
 
Last edited:
Thanks, that is useful, now I must just figure out how to parse the output from that module to get the one I want to be logged. :)

I get:

41.213.60.125
127.0.0.1
192.168.250.1

I want to save the 192.168.250.1 into a field called IP on each record in a table. I suppose I need to set each IP address as a global variable? How would I do that, I am not that sharp in VBA....

This module has helped a lot in getting there.

Brian

Based on what you received, I'd say

41.213.60.125 - is the address of your router on the Internet

127.0.0.1 - is a default address on your local PC (like running IIS or similar on a single machine)

192.168.250.1 - is the address of your PC on your local network behind your router


What is the purpose of the Table you want? eg "I want to save the 192.168.250.1 into a field called IP on each record in a table."


Here's a small procedure to get the IP addresses and to place the addresses into a Public variable with a CrLf between each IP address.

NOTE:

1) I declared a Public variable gIPAddrs

Code:
 Public gIPAddrs As String
2) I modified the GetIPAddresses procedure to put the IP addresses and CrLf
into the Public variable gIPAddrs.
In the GetIPAddresses procedure, look for
Debug.Print strIPAddress
then insert
Code:
                gIPAddrs = gIPAddrs & vbCrLf & strIPAddress


Here is my Small Procedure:
Code:
'---------------------------------------------------------------------------------------
' Procedure : test_GetIP
' Author    : user
' Date      : 3/15/2008
' Purpose   : To use the GetIPAddresses procedure
'             to get all IP addresses on users machine,
' and to display the IPs in the immediate window, and
'to place the IP addresses into a Global Public variable
' with a CrLf between each IP address.
'---------------------------------------------------------------------------------------
'
Sub test_GetIP()
   On Error GoTo test_GetIP_Error

'Initialize the public variable - gIPAddrs - to Null
gIPAddrs = vbNullString
' Invoke the proc to get IP addresses
GetIPAddresses

'Display the results in a msgbox
MsgBox gIPAddrs

   On Error GoTo 0
   Exit Sub

test_GetIP_Error:

    MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure test_GetIP of Module Module4"
End Sub


You could check gIPAddrs for the one containing 192. and
insert that value into the Table you discussed.

Good luck
 
Simple Software Solutions

Hi

Is the IP address for each PC Static? if not then you cannot historically truly identify the source pc. Would it not be better to save the computer name for your auditing purposes? In my LAN systems I not only capture the PC Name but also capture the windows login name, the application login name, the application login password (Encrypted) and the Date and Time of the login. This gives me full traceability for all transactions, logins, failed logins, deletions, etc.

CodeMaster::cool:
 
Hmm

DCrake, may I ask how you were able to get the computer Tag? I have the problem you were describing, we are all assigned DHCP Ips, which does no good. Is there a VBA function to retrieve this info from your LAN systems, or is it something available through the LAN? We use Novell, and I cannot for the life of me find any available computer names...

Thanks,

P.S. Long time reader, but I registered just to ask! This is an impressive task you've accomplished!
 
Simple Software Solutions

Hi

First you need the following declarations in your start up module

Code:
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Next declare two Global Variables in the declarations section:

Public StrComputerName As String
Public StrWindowsUserName As String


Next Create the following functions in your start up module

Code:
Function FindUserName() As String
    ' This procedure uses the Win32API function GetUserName
    ' to return the name of the user currently logged on to
    ' this machine. The Declare statement for the API function
    ' is located in the Declarations section of this module.
    
    Dim strBuffer As String
    Dim lngSize As Long
        
    strBuffer = String(100, " ")
    lngSize = Len(strBuffer)
    
       
    strBuffer = String(100, " ")
    lngSize = Len(strBuffer)
    
    If GetUserName(strBuffer, lngSize) = 1 Then
        FindUserName = Left(strBuffer, lngSize)
    Else
        FindUserName = "User Name not available"
    End If

 End Function


Code:
Public Function FindComputerName()
    Dim strBuffer As String
    Dim lngSize As Long
        
    strBuffer = String(100, " ")
    lngSize = Len(strBuffer)

    If GetComputerName(strBuffer, lngSize) = 1 Then
        FindComputerName = Left(strBuffer, lngSize)
    Else
        FindComputerName = "Computer Name not available"
    End If
    
End Function

Finally, on your login screen on the OnLoad Event place the following code:

Code:
StrComputerName = FindComputerName()
StrWindowsUserName = FindUserName()

You have now identified which computer has opened the application and which user was logged onto the computer. Bear in mind this may not be the person who opens the mdb. This is why I also capture that at the login screen. So this gives me full traceability for auditiing purposes.

David:
 
Thanks!

I have been using the GetComputerName api for a while, and by the time we find out where the ambiguous comuter name actually resides, the person has quit!

This will come in very handy! I am going to try to find a way to place it in the OnDirty of all of the fields that will be edited.

Thanks again, I'll let you know how it goes.
 
Hah, unfortunately 9/10 times the username is Administrator. I will go search for a Novell login API. Thanks for the help!
 
Simple Software Solutions

I am using Novel 4.91 :confused: is your front end on each users PC:confused:

Are you getting the correct pc name?

Do users all login with individual passwords

Passwords are like toothbrushes.....

You should use tthem all the time
Change them regularly
Don't let anyone else use them

David
 
You may have already seen this, but this captures the asset number and login details for us.

Code:
  DoCmd.SetWarnings False
    Dim oNet, ocomp As Object
    Set oNet = CreateObject("WScript.Network")
    Set ocomp = CreateObject("WScript.Network")
    UserName = oNet.UserName
    computername = ocomp.computername
    If (IsNull(DLast("[LoggedOut]", "Usage", "[UserName] ='" & Me.UserName & "'"))) Then
            If MsgBox("Please remember to close the BP Database using the 'Exit' button" & Chr(13) & Chr(10) & "Thank you for your co-operation.", vbInformation, "Info") = vbOK Then
            End If
    End If
    DoCmd.OpenQuery "qryUpdateUsage", acViewNormal
        If (IsNull(DLookup("[Name]", "BPDUsers", "[Login ID] ='" & Me.UserName & "'"))) Then
            Me.Caption = "UNKNOWN USER - Welcome to the BP Database"
        Else
            Me.Caption = DLookup("[Name]", "BPDUsers", "[Login ID] ='" & Me.UserName & "'") & " - Welcome to the BP Database"
        End If
    DoCmd.SetWarnings True

I have not changed details so it's 'as is'. The query "qryUpdateUsage", will add a log of when the user opened the Db and machine details.
 

Users who are viewing this thread

Back
Top Bottom