Tinha até esquecido de atualizar este tópico. mas eu achei o que precisava. Agora os CODES que utilizo são estes, para que se interessar:
CARREGAR ARQUIVO DO PC NO ACCESS COMO ANEXO
Sub CARREGAR_Anexo_NO_ACCESS()
'########################################################################
'# Nos testes realizados, foram utilizados as referências: #
'# #
'# 1. Microsoft Office xx.0 Access database engine Object Libary #
'# #
'########################################################################
Dim DaoDB As DAO.Database
Dim DaoRS As DAO.Recordset
Dim rsATT As DAO.Recordset2
Set DaoDB = DBEngine.OpenDatabase("ENDEREÇO DO BANCO ACCESS", False, False)
Set DaoRS = DaoDB.OpenRecordset("TABELA-OU-CONSULTA", dbOpenDynaset)
'####################################################################################################################
'# SE O BANCO DE DADO POSSUIR SENHA UTILIZA O COMENTÁRIO SEGUINTE NO LUGAR DO CODE ANTERIOR #
'# #
' Set DaoDB = DBEngine.OpenDatabase("ENDEREÇO DO BANCO ACCESS", False, False, Connect:="MS Access;PWD=" & "SENHA")
'# #
'####################################################################################################################
'##################################################################
'# ##
'# INSERIR O CODE PARA MOVIMENTAR ATÉ A LINHA DESEJADA DO BANCO ##
'# ##
'##################################################################
'##################################################################
'# ##
'# EXEMPLO DA BUSCA POR UM REGISTRO ##
' DaoRS.FindFirst "[Nome] LIKE 'Pedro'" ##
'# ##
'##################################################################
'Ativar modo de edição da Recordset principal
DaoRS.Edit
' Inicia uma Child-Recordset na FIELD que possuirá o ANEXO
Set rsATT = DaoRS.Fields("NOME DA FIELD").Value
'Adiciona o anexo na field do RecordSet principal
'FileData refere-se a field da ChildRecordset (Rescordset2).
rsATT.AddNew
rsATT.Fields("FileData").LoadFromFile "ENDEREÇO DO ANEXO" 'INSERIR O ENDEREÇO DO ANEXO
'Atualizar Recordset2
rsATT.Update
'Atualizaro o Recordset principal
DaoRS.Update
'*********************************************************************************
'FIM DO CODE
'******************************************************************************
rsATT.Close
DaoRS.Close
DaoDB.Close
Set rsATT = Nothing
Set DaoRS = Nothing
Set daosb = Nothing
MsgBox "Anexo incluidos com sucesso!", vbOKOnly, "Processo concluído"
Exit Sub
TratarErro:
Set rsATT = Nothing
Set DaoRS = Nothing
Set daosb = Nothing
MsgBox "Erro Nº: " & Err.Number & vbNewLine & _
"Descrição: " & Err.Description, vbCritical, "Erro - ACCESS ACCDB"
End Sub
SALVAR ANEXO DO ACCESS NO PC
Sub SALVAR_Anexo_DO_ACCESS()
'########################################################################
'# Nos testes realizados, foram utilizados as referências: #
'# #
'# 1. Microsoft Office xx.0 Access database engine Object Libary #
'# #
'########################################################################
Dim DaoDB As DAO.Database
Dim DaoRS As DAO.Recordset
Dim rsATT As DAO.Recordset2
Set DaoDB = DBEngine.OpenDatabase("ENDEREÇO DO BANCO DE DADOS", False, False)
Set DaoRS = DaoDB.OpenRecordset("NOME DA TABELA NO BANCO", dbOpenDynaset)
'####################################################################################################################
'# SE O BANCO DE DADO POSSUIR SENHA UTILIZA O COMENTÁRIO SEGUINTE NO LUGAR DO CODE ANTERIOR #
'# #
' Set DaoDB = DBEngine.OpenDatabase("ENDEREÇO DO BANCO ACCESS", False, False, Connect:="MS Access;PWD=" & "SENHA")
'# #
'####################################################################################################################
'##################################################################
'# ##
'# INSERIR O CODE PARA MOVIMENTAR ATÉ A LINHA DESEJADA DO BANCO ##
'# ##
'##################################################################
'##################################################################
'# ##
'# EXEMPLO DA BUSCA POR UM REGISTRO ##
' DaoRS.FindFirst "[Nome] LIKE 'Pedro'" ##
'# ##
'##################################################################
'Inicia uma Child-Recordset na FIELD que possui o ANEXO
Set rsATT = DaoRS.Fields("Anexos").Value
'LOOP em todos os anexos e salvo na pasta especificada
Do
'Salva o anexo no endereço especificado
rsATT.Fields("FileData").SaveToFile "C:Documents and Settings617018Desktop"
rsATT.MoveNext
Loop Until rsATT.EOF 'Irá verificar se moveu-se além do registro
'******************************************************************************
'FIM DO CODE
'*********************************************************************************
rsATT.Close
DaoRS.Close
DaoDB.Close
Set rsATT = Nothing
Set DaoRS = Nothing
Set daosb = Nothing
MsgBox "Anexo salvos com sucesso!", vbOKOnly, "Processo concluído"
Exit Sub
TratarErro:
Set rsATT = Nothing
Set DaoRS = Nothing
Set daosb = Nothing
MsgBox "Erro Nº: " & Err.Number & vbNewLine & _
"Descrição: " & Err.Description, vbCritical, "Erro - ACCESS ACCDB"
End Sub
Pietro Farias
Se foi resolvido suas dúvidas, lembre se de marcar o tópico como RESOLVIDO.
ANALISTA X
Postado : 24/05/2016 11:15 am