RE:SQL a un archivo de texto
1.- Cargas los registros de SQL en una variable RecordSet en Visual basic
Funcion para cargar un recorset :
Public Function fRetornaRS(GsSentenciaSQL As String) As ADODB.Recordset
Dim Cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
On Error GoTo Msj_error
rs.CursorLocation = adUseClient
With Cmd
.ActiveConnection = "provider=sqloledb;data source=BE02;uid=contable;database=PRUEBAS;pwd=contable;"
.CommandType = adCmdText
.CommandText = GsSentenciaSQL
.Execute
End With
rs.Open Cmd, , adOpenDynamic, adLockOptimistic
Set fRetornaRS = rs
Set rs = Nothing
Set Cmd = Nothing
Msj_error:
If Err.Number <> 32755 Then
If Len(Err.Description) > 1 Then MsgBox "Ocurrió el Siguiente Error:" + Chr(13) + Err.Description, vbCritical, "SISTEMA"
End If
End Function
CARGAS EJEMPLO:
DIM RSClientes as New ADODB.recordset
fRetornaRS ("SELECT * FROM CLIENTES")
' un select a la tabla clientes que tiene los campos : NombreCli y RUC
2.- Luego por ejemplo en un boton
Open "c:Archivo.txt" For Append As #1
for i = 0 to RS.recordcount -1 ' Aqui recorres la lista de registros de tu select
Print #1, RS!NombreCli & " " & RsRUC
next
Close #1
Bien espero te ayude,
Saludos
Rolando