?
Solved

Using VBA to produce output from NSLOOKUP

Posted on 2006-11-03
7
Medium Priority
?
1,446 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:tilacakr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 2

Accepted Solution

by:
eheimer earned 1000 total points
ID: 17870861
try this:

dim ipaddrs()
dim outputfile as string
outputfile = "c:\nslookup.out"

'insert commands to load ip addresses from file into array

'the command below will append output to the outputfile.  If you want to
'make sure you're starting with a new file, insert command to delete existing file here.

for x = 0 to ubound(ipaddrs) - 1
      Shell Environ$("COMSPEC") & " /c nslookup " & ipaddrs(x) & " >> " & outputfile, 1
next x
0
 

Author Comment

by:tilacakr
ID: 17882253
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
0
 

Author Comment

by:tilacakr
ID: 17883464
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tilacakr
ID: 17883723
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
0
 

Author Comment

by:tilacakr
ID: 17883981
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
0
 

Author Comment

by:tilacakr
ID: 17884161
Correction...

Actually only getting one output despite having many lines to query. They are just concatenating onto the existing file.
0
 
LVL 2

Expert Comment

by:eheimer
ID: 17886510
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.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question