Vba commands used to connect to sql


Answer this question

Vba commands used to connect to sql

  • RobKinney1

    Thnx Derek... I tried the commands but an error message appear "ActiveX component can't create object" and i don't know how to solve this problem.

  • NicMilne

    Thats a bit odd... try the Open statement instead. Here's an example:

    Dim I, FileName
    For I = 1 To 3  ' Loop 3 times.
      FileName = "TEST" & I  ' Create file name.
      Open FileName For Output As #I  ' Open file.
      Print #I, "This is a test."  ' Write string to file.
    Next I
    Close  ' Close all 3 open files.
    
    The important lines are Open, Print and Close. 
    Look in the help file for the open statement as there are a few options to opening the file.
    That will work.


  • Yes!

    HI,

    Use the FileSystemObject...

    Sub OpenTextFileTest
      Const ForReading = 1, ForWriting = 2, ForAppending = 3
      Dim fs, f
      Set fs = CreateObject("Scripting.FileSystemObject")
      Set f = fs.OpenTextFile("c:\testfile.txt", ForAppending,TristateFalse)
      f.Write "Hello world!"
      f.Close
    End Sub
    


  • ManServ

    thnx Derek ......

    i've tried the commands and it works...

    thnx again for being so kind in giving us new ideas....



  • Vba commands used to connect to sql