File format

R

Rodney

Ok, I have some code that on a Button click will check
the Service Pack Version of the given computer in the
Str=Me.Form.Controls.Item("[Cmp Name]") line, and write
it to a text file called test.txt.

So the file ends up looking like this:

ServicePackVersion
4.0
acct1 (computer name)


Now a few questions:

#1, Am I able to write this to a table instead?

#2, If I can't write directly to a table, then in the
code, can I format it comma delimited so it's easy to
import?


Here's my code below. Thanks

Private Sub Command14_Click()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile
("c:\scripts\test.txt", True)
strComputer = Me.Form.Controls.Item("[Cmp Name]")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer
& "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("SELECT * FROM Win32_OperatingSystem")
objTextFile.WriteLine "ServicePackVersion"
For Each objOperatingSystems In colOperatingSystems
objTextFile.WriteLine
objOperatingSystems.ServicePackMajorVersion _
& "." &
objOperatingSystems.ServicePackMinorVersion
objTextFile.WriteLine Me.Form.Controls.Item("[Cmp Name]")
Next
objTextFile.Close
End Sub
 
J

JohnFol

#1 Yes, just build up a query string and do a Docmd.RunQuery

#2 Instead of having multiple objTextFile.WriteLine, just build up a string

ie Dim strLineToWrite as string
strLineToWrite = "ServicePackVersion," & ServicePackMajorVersion & "." &
objOperatingSystems.ServicePackMinorVersion & ","
Me.Form.Controls.Item("[Cmp Name]")

objTextFile.WriteLine strLineToWrite
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top