Link to home
Start Free TrialLog in
Avatar of tilacakr
tilacakr

asked on

Using VBA to produce output from NSLOOKUP

I'm trying to use a command button in MS Access (as I don't have VB installed at work) to do the following:

1. Open a text file containing IP Addresses
2. Run NSLOOKUP (an executable that displays info for each IP address on screen) against each IP address
3. Print the returned info for each IP Address to a new text file and do this until reaching the end of the IP Address file.

I'm familiar with how to open a file for input and output, but not with how to run the NSLOOKUP from code or how to print the output of the NSLOOKUP to a new text file.

Any help is appreciated.

Tim
ASKER CERTIFIED SOLUTION
Avatar of eheimer
eheimer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tilacakr
tilacakr

ASKER

Refresh my memory...

I know how to open a file for input and output, but forgot how to load it into an array.

Thanks,
Tim
Eric,

I'm trying this code reading a line at a time in as I'm familiar with how to do that and my text file will only contain IP addresses. Do you think this will work?

Private Sub Command0_Click()

Dim ff As Integer
Dim outputfile As String
outputfile = "c:\ipconfig.out"

ff = FreeFile
Path = "C:\WINDOWS\System32\ipconfig.exe"

Open "C:\Tim\Test.txt" For Input As #ff

Do Until EOF(ff)
Line Input #ff, ln

Shell Environ$("COMSPEC") & " /c ipconfig " & ln & " >> " & outputfile

DoEvents
Loop

Close #ff

End Sub
Eric,

Actually I just tested the code (should've done that before my last post) and it worked.

Thanks for the help with the output file.

Tim
Eric,

I know I closed this out, but I think I still may have something missing. I took out the ", 1" you had after the ling:

Shell Environ$("COMSPEC") & " /c ipconfig " & ln & " >> " & outputfile

and I only got the first option I used for Ipconfig (have to use IPCONFIG as I'm writing this for someone who has access to nslookup and I do not). I placed the ", 1" back in and I got output to my outputfile of two of the four options.

What is the purpose of the comma and subsequent number in the code?

Thanks,
Tim
Correction...

Actually only getting one output despite having many lines to query. They are just concatenating onto the existing file.
Sorry for my absense today.  The syntax of the "shell" command is:

Shell (pathname, [windowstyle])

The arguments for windowstyle are:

0 = hide the window
1 = normal focus
2 = minimized with focus
3 = maximized
4 = normal, no focus
6 = minimized, no focus

It doesn't sound like that is related to your problem, though.  I see you have another question opened for this issue.  I'll take a look at it there.