Consulta do while not
Publicado por Mariel (11 intervenciones) el 19/01/2012 14:16:50
Que tal amigos, sigo con el mismo inconveniente... pero creo que avancé un paso...
El tema es así, tengo dos tablas SOCIOS y ACTIVIDADES, debo exportar un archivo txt que debe tener este formato
SOCIO
7423,,,11,0,0,0,1,0,20/10/2011,,,,,1,0,4,155033147906,,,,
ACTIVIDADES
7423,,,,0,1,F20.5,1,
7423,,,,0,1,F20.5,1,
7423,,,,0,1,F20.5,1,
SOCIO
1823,,,11,0,0,0,1,0,02/11/2011,,,,,1,0,4,1550326354,,,,
ACTIVIDADES
1823,,,,0,1,F19.5,1,
1823,,,,0,1,F19.5,1,
Realicé la exportación de la tabla socios bien, lo hice con un bucle, el problema es cuando quiero agregar todas las actividades, lo intento haciendo otro bucle dentro del primero, pero hasta ahora lo
que he logrado es que me en ACTIVIDADES me devuelva todas las actividades de todos los socios, cuando en realidad solo quiero que devuelva lo del que colocó al principio he intentado agregando
strSQL1 = strSQL1 & "select * FROM ACTIVIDADES RIGHT JOIN SOCIOS ON ACTIVIDADES.NROSOCIO = SOCIOS.NROSOCIO"
strSQL1 = strSQL1 & " WHERE (((ACTIVIDADES.NROSOCIO)= SOCIOS.NROSOCIO))"
Pero me tira error 3061 en proc.cmdExportar_Click de Documento VBA Form_Formulario1 (pocos parámetros, se esperaba 1.)
Este es mi código como está hoy.....
Private Sub cmdExportar_Click()
On Error GoTo cmdExportar_Click_TratamientoErrores
Dim strArchivo As String, _
bytArchivo As Byte, _
strLinea As String, _
rst As Recordset, _
rst1 As Recordset, _
strSQL As String, _
strSQL1 As String, _
strDelimitador As String
strDelimitador = Chr(ccDelimitador.Column(1))
strSQL = "SELECT * FROM SOCIOS"
' abro el recordset
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
bytArchivo = FreeFile
' obtengo el archivo a exportar del cuadro de texto
strArchivo = txtRuta
' abro el archivo de texto
Open strArchivo For Output As bytArchivo
If Not rst.EOF And Not rst.BOF Then
Print #bytArchivo, "SOCIOS"
Do While Not rst.EOF
' ' exporto cada registro en una linea de texto
Print #bytArchivo, rst!NROSOCIO& strDelimitador & "" _
; rst!FECHAEMUL & strDelimitador & "" _
; rst!MES & strDelimitador & "" _
; rst!ANIO & strDelimitador & "" _
; rst!RAZON & strDelimitador & "" _
; rst!USUARIO & strDelimitador & "" _
; rst!NROINSTALA & strDelimitador
Print #bytArchivo, "ACTIVIDADES"
strSQL1 = "SELECT * FROM ACTIVIDADES"
Set rst1 = CurrentDb.OpenRecordset(strSQL1, dbOpenDynaset)
If Not rst1.EOF And Not rst1.BOF Then
Do While Not rst1.EOF
' exporto cada registro en una linea de texto
Print #bytArchivo, rst1!NROSOCIO & strDelimitador & ""; _
; rst1!Vacio1 & strDelimitador & ""; _
; rst1!Vacio2 & strDelimitador & ""; _
; rst1!Vacio3 & strDelimitador & ""; _
; rst1!c_ambulatorio & strDelimitador & ""; _
; rst1!ni_codpresta & strDelimitador & ""; _
; rst1!vch_codprestacion & strDelimitador & ""; _
; rst1!f_fecha_practica & strDelimitador & ""; _
; rst1!q_cantidad & strDelimitador & ""; _
; rst1!c_prestador_solicita & strDelimitador & ""; _
; rst1!c_profesional_solicita & strDelimitador
rst1.MoveNext
' rst1.Close
Loop
End If
rst.MoveNext
Loop
End If
cmdExportar_Click_Salir:
On Error GoTo 0
Close #bytArchivo
If Not IsEmpty(rst) Then
rst.Close
Set rst = Nothing
End If
Exit Sub
cmdExportar_Click_TratamientoErrores:
MsgBox "Error " & Err.Number & " en proc. cmdExportar_Click de Documento VBA Form_Formulario1 (" & Err.Description & ")", vbOKOnly + vbCritical
GoTo cmdExportar_Click_Salir
End Sub
Gracias!!!!
El tema es así, tengo dos tablas SOCIOS y ACTIVIDADES, debo exportar un archivo txt que debe tener este formato
SOCIO
7423,,,11,0,0,0,1,0,20/10/2011,,,,,1,0,4,155033147906,,,,
ACTIVIDADES
7423,,,,0,1,F20.5,1,
7423,,,,0,1,F20.5,1,
7423,,,,0,1,F20.5,1,
SOCIO
1823,,,11,0,0,0,1,0,02/11/2011,,,,,1,0,4,1550326354,,,,
ACTIVIDADES
1823,,,,0,1,F19.5,1,
1823,,,,0,1,F19.5,1,
Realicé la exportación de la tabla socios bien, lo hice con un bucle, el problema es cuando quiero agregar todas las actividades, lo intento haciendo otro bucle dentro del primero, pero hasta ahora lo
que he logrado es que me en ACTIVIDADES me devuelva todas las actividades de todos los socios, cuando en realidad solo quiero que devuelva lo del que colocó al principio he intentado agregando
strSQL1 = strSQL1 & "select * FROM ACTIVIDADES RIGHT JOIN SOCIOS ON ACTIVIDADES.NROSOCIO = SOCIOS.NROSOCIO"
strSQL1 = strSQL1 & " WHERE (((ACTIVIDADES.NROSOCIO)= SOCIOS.NROSOCIO))"
Pero me tira error 3061 en proc.cmdExportar_Click de Documento VBA Form_Formulario1 (pocos parámetros, se esperaba 1.)
Este es mi código como está hoy.....
Private Sub cmdExportar_Click()
On Error GoTo cmdExportar_Click_TratamientoErrores
Dim strArchivo As String, _
bytArchivo As Byte, _
strLinea As String, _
rst As Recordset, _
rst1 As Recordset, _
strSQL As String, _
strSQL1 As String, _
strDelimitador As String
strDelimitador = Chr(ccDelimitador.Column(1))
strSQL = "SELECT * FROM SOCIOS"
' abro el recordset
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
bytArchivo = FreeFile
' obtengo el archivo a exportar del cuadro de texto
strArchivo = txtRuta
' abro el archivo de texto
Open strArchivo For Output As bytArchivo
If Not rst.EOF And Not rst.BOF Then
Print #bytArchivo, "SOCIOS"
Do While Not rst.EOF
' ' exporto cada registro en una linea de texto
Print #bytArchivo, rst!NROSOCIO& strDelimitador & "" _
; rst!FECHAEMUL & strDelimitador & "" _
; rst!MES & strDelimitador & "" _
; rst!ANIO & strDelimitador & "" _
; rst!RAZON & strDelimitador & "" _
; rst!USUARIO & strDelimitador & "" _
; rst!NROINSTALA & strDelimitador
Print #bytArchivo, "ACTIVIDADES"
strSQL1 = "SELECT * FROM ACTIVIDADES"
Set rst1 = CurrentDb.OpenRecordset(strSQL1, dbOpenDynaset)
If Not rst1.EOF And Not rst1.BOF Then
Do While Not rst1.EOF
' exporto cada registro en una linea de texto
Print #bytArchivo, rst1!NROSOCIO & strDelimitador & ""; _
; rst1!Vacio1 & strDelimitador & ""; _
; rst1!Vacio2 & strDelimitador & ""; _
; rst1!Vacio3 & strDelimitador & ""; _
; rst1!c_ambulatorio & strDelimitador & ""; _
; rst1!ni_codpresta & strDelimitador & ""; _
; rst1!vch_codprestacion & strDelimitador & ""; _
; rst1!f_fecha_practica & strDelimitador & ""; _
; rst1!q_cantidad & strDelimitador & ""; _
; rst1!c_prestador_solicita & strDelimitador & ""; _
; rst1!c_profesional_solicita & strDelimitador
rst1.MoveNext
' rst1.Close
Loop
End If
rst.MoveNext
Loop
End If
cmdExportar_Click_Salir:
On Error GoTo 0
Close #bytArchivo
If Not IsEmpty(rst) Then
rst.Close
Set rst = Nothing
End If
Exit Sub
cmdExportar_Click_TratamientoErrores:
MsgBox "Error " & Err.Number & " en proc. cmdExportar_Click de Documento VBA Form_Formulario1 (" & Err.Description & ")", vbOKOnly + vbCritical
GoTo cmdExportar_Click_Salir
End Sub
Gracias!!!!
Valora esta pregunta


0