vbscript update multi value record

sgdought
sgdought used Ask the Experts™
on
I'm trying to record the IP address of computers into an access database.  I need to record all IP address of a computer.  The problem is the lasdt IP address over writes the first one.  how does one put multiple entries in an access database with vbscript (similiar to press Ctrl+Alt and adding a second entry manually).
Option Explicit
'On Error Resume Next
Const ForRead = 1    'Opens file for reading
Const ForWriting = 2 'Opens file for writing, overwriting file
Const ForAppend = 8  'Opens file for Appending
Const OverwriteExisting = True
Const NoOverWrite = False
Const strServerIP = "10.121.4.5"
 
 
'* Declare Variables
Dim strComputer, strText, objLogFile, strServerPath
Dim strTime, strDate, strTemp
Dim objShell, objWMIService, objExecObject, objFSO
Dim objConnection, objRecordSetAddress
 
strComputer = "."    '* This computer
    
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
'objFSO.OpenTextFile("C:\temp\address1.txt")
Set objLogFile=objFSO.OpenTextFile("C:\temp\address1.txt", ForAppend)
Err.Clear
Set objShell = WScript.CreateObject("Wscript.Shell")
 
 
'* Constants defing parameters for the DB object open method
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
 
'* Set connections to ADO DataBase objects
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSetAddress = CreateObject("ADODB.Recordset")
 
'* Open connection to Database
'* To use change the 2nd line below to match the server name
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Scripts\Address1.mdb"
 
objRecordSetAddress.CursorLocation = adUseClient
 
'* Connect to table
objRecordSetAddress.Open "SELECT * FROM Address_Table" , objConnection, _
 adOpenStatic, adLockOptimistic
 
objRecordSetAddress.AddNew
strTime = FormatDateTime(Now(),vbLongTime)
Err.Clear
objRecordSetAddress("LoginTime") = strTime
'* WScript.Echo "strTime is " & strTime
objLogFile.WriteLine strTime
strDate = FormatDateTime(Now(),vbShortDate)
objRecordSetAddress("LoginDate") = strDate
'* WScript.Echo "strDate is " & strDate
objLogFile.WriteLine strDate
 
Set objExecObject = objShell.Exec ("ipconfig /all")
Do While objExecObject.Status <> 1
     strText = objExecObject.StdOut.ReadLine
     If InStr(strText,"Host Name") Then
          objRecordSetAddress("HostName") = strText
          objLogFile.WriteLine strText
     End If 
     
     If InStr(strText,"IP Address") Then
         strTemp = objRecordSetAddress.Fields.Item("IPAdress")
         strTemp = strTemp & ", " & strText
         objRecordSetAddress("IPAdress") = strTemp 
     End If
      
     If InStr (strText, "IPv4") Then
           objRecordSetAddress("IPAddress") = strText
           objLogFile.WriteLine strText
     End If 
     
     If InStr(strText,"Physical") Then
          objRecordSetAddress("NicAddress") = strText
          objLogFile.WriteLine strText
     End If
                   
Loop
 
Set objExecObject = objShell.Exec ("cmd.exe /c set")
Do While objExecObject.Status <> 1
     strText = objExecObject.StdOut.ReadLine
     
     If InStr(strText,"USERNAME") Then
           objRecordSetAddress("Username") = strText
     End If
 
                   
Loop
objRecordSetAddress.update
objLogFile.WriteLine "***************************************************************"
objLogFile.Close

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
you will probably want to use objRecordSetAddress.addnew to add a new record instead of editing the current record

Commented:
or execute an "insert into" statement

Author

Commented:
Line 49 adds the new record using the add new function..  What I'm trying to do is add multiple IP addresses to the same cell, appending the second IP address  instead of overwriting the first address that was put into the database record.  As you can see from lines 68 to 71 I was trying to concatenate the 2 IP addreses, but what I really want is both IP addresses in the same cell.  Currently the second IP address (say the wireless address), overwrites the first address, the wired address.  
So basically I'm trying to update an access record field with multiple values, using vbscript.
Commented:
Never did find a solution to adding multiple values to a field through vbscript.  So I rewrote the code to add a complete record for each IP address, instead of the more efficient method of using a multi value field.

Author

Commented:
Solution requested ws not found, I found an alternate solution on my own

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial