Generar un cuaderno bancario Q19 con access
Adapta esta función a tus necesidades
Private Sub CSB19_Click()
Dim DatOrd(4) As String
Dim strSQL As String
Dim MI_BD As Database
Dim MI_rs As Recordset
Dim IMPORTES As String, pos As Integer
Dim TotalTrans As Currency, nro110 As Integer, nroTotal As Integer
Dim TOTAL As String
Screen.MousePointer = 11
Set MI_BD = DBEngine.Workspaces(0).Databases(0)
strSQL = "SELECT NDNI, NOMB, DOMI, CPOS, PBLA, BANC, SUCU, CUEN, IMPORTE FROM [REMESA DE CARGOS CS] WHERE IMPORTE > 0"
Set MI_rs = MI_BD.OpenRecordset(strSQL)
DatOrd(0) = "31111111X"
DatOrd(1) = Format(Date, "ddmmyy")
DatOrd(2) = "21030000001234567890" '20 digitos
DatOrd(3) = "Comunidad de vecinos"
Open "C:\ACCESS2003\Ficherito.C34" For Output As #1
'Cabecera del fichero del CSB
Print #1, "5180"; DatOrd(0); "000"; DatOrd(1); Tab(26); DatOrd(3); Tab(89); Left(DatOrd(2), 8)
Print #1, "5380"; DatOrd(0); "000"; DatOrd(1); DatOrd(1); DatOrd(3); Tab(69); DatOrd(2); Tab(97); "01"
Do While Not MI_rs.EOF
'Transforma importe
IMPORTES = CStr(Format(MI_rs("IMPORTE"), "#.00"))
pos = InStr(1, IMPORTES, ",")
IMPORTES = Left(IMPORTES, pos - 1) & Mid(IMPORTES, pos + 1, 2)
IMPORTES = String(10 - Len(IMPORTES), "0") & IMPORTES
'Transforma la ctaBancaria si es necesario
Dim ctaBenef As String
ctaBenef = MI_rs("BANC") & MI_rs("SUCU") & MI_rs("CUEN")
Print #1, "5680"; DatOrd(0); "000"; MI_rs("NDNI"); Tab(29); MI_rs("NOMB"); Tab(69); ctaBenef; IMPORTES; Tab(115); "Honorarios Habilitación Gil"
Print #1, "5686"; DatOrd(0); "000"; MI_rs("NDNI"); Tab(29); MI_rs("NOMB"); Tab(69); MI_rs("DOMI"); Tab(109); MI_rs("PBLA"); Tab(142); MI_rs("CPOS")
TotalTrans = TotalTrans + MI_rs("IMPORTE")
nro110 = nro110 + 1
MI_rs.MoveNext
Loop
'Registros de totales del CSB
TOTAL = Format(TotalTrans, "#.00")
pos = InStr(1, TotalTrans, ",")
TOTAL = Left(TOTAL, pos - 1) & Mid(TOTAL, pos + 1, 2)
TOTAL = String(10 - Len(TOTAL), "0") & TOTAL
nroTotal = 2 + nro110 * 2
Print #1, "5880"; DatOrd(0); "000"; Tab(89); TOTAL; Tab(105); String(10 - Len(CStr(nro110)), "0") & nro110; String(10 - Len(CStr(nroTotal)), "0") & nroTotal
nroTotal = 4 + nro110 * 2
Print #1, "5980"; DatOrd(0); "000"; Tab(69); "0001"; Tab(89); TOTAL; Tab(105); String(10 - Len(CStr(nro110)), "0") & nro110; String(10 - Len(CStr(nroTotal)), "0") & nroTotal
Close #1
MI_rs.Close
Set MI_rs = Nothing
Screen.MousePointer = 0
Call MsgBox("Se ha creado el fichero de transferencias en formato CSB", vbInformation, "Fichero CSB19")
End Sub