[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Dim oStream As ADODB.Stream
Set cn = New ADODB.Connection
'Here I use default admin user 'sa' and password is blank
cn.Open "Provider = sqloledb;" & _
"Data Source=ServerNameOrIP;" & _
"Initial Catalog=DBName;" & _
"User ID=sa;" & _
'your sql statment including varbinary max field here it is FILEDATA
sql = " select EMAILID,EMAILFROM,EMAILTO,EMAILSUBJECT,FILEDATA from Tbl "
Set rs = New ADODB.Recordset
rs.Open sql, cn
Do Until rs.EOF
Set oStream = New ADODB.Stream
.Type = adTypeBinary
'Here I use 1st field value as file name i.e. rs.fiedls(0).value
'In addition you can join drive and/or folder path to save another location
.SaveToFile rs.Fields(0).Value & ".pdf", adSaveCreateOverWrite
Set oStream = Nothing
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.