Problema con Open binary access
Publicado por Edwin Thomas (4 intervenciones) el 04/01/2006 00:15:09
Tengo una aplic. en access en la que en una tabla cargo los datos binarios de X archivo y los extraigo para guardarlos en otra ubicación. El problema es que al querer abrir el archivo el programa asociado (imagen, mdb, etc.) no lo abre pero el tamaño del archivo es el mismo. Cuando se trata de un archivo.txt lo abre el block de notas pero le agrega al texto del archivo algunos caracteres especiales. Como si corropiera los archivos que procesa.
Las dos funciones que ocupo son las siguintes:
Function Empaqueta()
Dim Rst As DAO.Recordset
On Error GoTo Etiqueta_Error
Set Rst = CurrentDb.OpenRecordset("TblFicherosAdjuntos")
While Rst.EOF = False
Dim CanalLibre As Long
Dim B() As Byte, StrLongitud&
CanalLibre = FreeFile
StrLongitud = FileLen(Rst("rutaficheroadjunto"))
ReDim B(StrLongitud - 1)
Open Rst("rutaficheroadjunto") For Binary Access Read As #CanalLibre
Get #CanalLibre, , B
Rst.Edit
Rst.Fields("CampoOleContenedor").AppendChunk B
Rst.Update
Close #CanalLibre
Rst.MoveNext
Wend
Rst.Close
Set Rst = Nothing
exit_EscribeDLLaTabla:
Set Rst = Nothing
Close
Exit Function
Etiqueta_Error:
Resume exit_EscribeDLLaTabla
End Function
Public Function EscribeInstaladorADisco(ByVal NombreTabla As String, ByVal NombreCampoTabla As String, ByVal NombreFichero As String) As Boolean
Dim B() As Byte, Rst As DAO.Recordset
Dim LongitudTotal&
On Error GoTo err_ControlError
Set Rst = CurrentDb.OpenRecordset(NombreTabla)
With Rst
If .RecordCount = 0 Then
GoTo err_ControlError
End If
LongitudTotal = .Fields(NombreCampoTabla).FieldSize
ReDim B(LongitudTotal)
'B = .Fields(NombreCampoTabla)
'la linea anterior la comentarie por que me da error: "Imposible asignar a una matriz"
'no se si ese será el problema. estas funciones se las copie a Emilio (Buho)
End With
Rst.Close
Open NombreFichero For Binary Access Write As #1
Put #1, , B
Close #1
EscribeInstaladorADisco = True
exit_ControlError:
Set Rst = Nothing
Close
Exit Function
err_ControlError:
EscribeInstaladorADisco = False
Resume exit_ControlError
End Function
Las dos funciones que ocupo son las siguintes:
Function Empaqueta()
Dim Rst As DAO.Recordset
On Error GoTo Etiqueta_Error
Set Rst = CurrentDb.OpenRecordset("TblFicherosAdjuntos")
While Rst.EOF = False
Dim CanalLibre As Long
Dim B() As Byte, StrLongitud&
CanalLibre = FreeFile
StrLongitud = FileLen(Rst("rutaficheroadjunto"))
ReDim B(StrLongitud - 1)
Open Rst("rutaficheroadjunto") For Binary Access Read As #CanalLibre
Get #CanalLibre, , B
Rst.Edit
Rst.Fields("CampoOleContenedor").AppendChunk B
Rst.Update
Close #CanalLibre
Rst.MoveNext
Wend
Rst.Close
Set Rst = Nothing
exit_EscribeDLLaTabla:
Set Rst = Nothing
Close
Exit Function
Etiqueta_Error:
Resume exit_EscribeDLLaTabla
End Function
Public Function EscribeInstaladorADisco(ByVal NombreTabla As String, ByVal NombreCampoTabla As String, ByVal NombreFichero As String) As Boolean
Dim B() As Byte, Rst As DAO.Recordset
Dim LongitudTotal&
On Error GoTo err_ControlError
Set Rst = CurrentDb.OpenRecordset(NombreTabla)
With Rst
If .RecordCount = 0 Then
GoTo err_ControlError
End If
LongitudTotal = .Fields(NombreCampoTabla).FieldSize
ReDim B(LongitudTotal)
'B = .Fields(NombreCampoTabla)
'la linea anterior la comentarie por que me da error: "Imposible asignar a una matriz"
'no se si ese será el problema. estas funciones se las copie a Emilio (Buho)
End With
Rst.Close
Open NombreFichero For Binary Access Write As #1
Put #1, , B
Close #1
EscribeInstaladorADisco = True
exit_ControlError:
Set Rst = Nothing
Close
Exit Function
err_ControlError:
EscribeInstaladorADisco = False
Resume exit_ControlError
End Function
Valora esta pregunta
0