将ACCESS的ole对象导出为文件

 

1.frm

VERSION  5.00
Begin VB.Form Form1 
   Caption         
=     " Form1 "
   ClientHeight    
=     3195
   ClientLeft      
=     60
   ClientTop       
=     345
   ClientWidth     
=     4680
   LinkTopic       
=     " Form1 "
   ScaleHeight     
=     3195
   ScaleWidth      
=     4680
   StartUpPosition 
=     3    ' Windows Default
   Begin VB.CommandButton Command2 
      Caption         
=     " Command2 "
      Height          
=     855
      
Left              =     1440
      TabIndex        
=     0
      Top             
=     1080
      Width           
=     1695
   
End
End
Attribute VB_Name 
=   " Form1 "
Attribute VB_GlobalNameSpace 
=   False
Attribute VB_Creatable 
=   False
Attribute VB_PredeclaredId 
=   True
Attribute VB_Exposed 
=   False

Option   Explicit
    
  
Private   Declare   Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As LongByVal lpOperation As StringByVal lpFile As StringByVal lpParameters As StringByVal lpDirectory As StringByVal nShowCmd As LongAs Long
  
Private Const SW_SHOW = 5
  
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
    
  
'保存
  Private Sub Command1_Click()
          
Dim bteContent()     As Byte
            
          Open 
"C:aa.DOC" For Binary Access Read As #1
          bteContent 
= InputB(LOF(1), #1)
          Close #
1
            
          
If rs.State = adStateOpen Then rs.Close
          rs.Open 
"select   *   from   tablename", cn, adOpenDynamic, adLockPessimistic
          rs.AddNew
          rs!Name 
= "张三"
          rs!AGE 
= 22
          rs!SEX 
= ""
          rs.Fields(
"PHOTO").AppendChunk bteContent
          rs.Update
            
          
Erase bteContent
  
End Sub

    
  
'打开
  Private Sub Command2_Click()
          
Dim bteContent()     As Byte
          
If rs.State = adStateOpen Then rs.Close
          rs.Open 
"select   *   from   tablename", cn, adOpenForwardOnly, adLockReadOnly
          bteContent 
= rs.Fields("PHOTO").GetChunk(rs.Fields("PHOTO").ActualSize)
    
          Open 
"F:.doc" For Binary Access Write As #1
          Put #
1, , bteContent
          Close #
1
          ShellExecute 
Me.hWnd, "open""F:.doc", vbNullString, vbNullString, SW_SHOW
  
End Sub

    
  
Private Sub Form_Load()
  
On Error GoTo Errhandle
          cn.ConnectionString 
= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:.mdb;Persist Security Info=False"
          cn.Open
            
          
Exit Sub
Errhandle:
          
MsgBox Err.Description, vbExclamation
  
End Sub

    
  
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  
On Error Resume Next
          rs.Close
          
Set rs = Nothing
          cn.Close
          
Set cn = Nothing
  
End Sub


 

1.vbp

Type = Exe
Form
= Form1.frm
Reference
=* G{ 00020430 - 0000 - 0000 - C000 - 000000000046 }# 2.0 # 0 #.. .. .. .. WINDOWS system32 stdole2.tlb#OLE Automation
Startup
= " Form1 "
Command32
= ""
Name
= " Project1 "
HelpContextID
= " 0 "
CompatibleMode
= " 0 "
MajorVer
= 1
MinorVer
= 0
RevisionVer
= 0
AutoIncrementVer
= 0
ServerSupportFiles
= 0
VersionCompanyName
= " cnpvp "
CompilationType
= 0
OptimizationType
= 0
FavorPentiumPro(tm)
= 0
CodeViewDebugInfo
= 0
NoAliasing
= 0
BoundsCheck
= 0
OverflowCheck
= 0
FlPointCheck
= 0
FDIVCheck
= 0
UnroundedFP
= 0
StartMode
= 0
Unattended
= 0
Retained
= 0
ThreadPerObject
= 0
MaxNumberOfThreads
= 1

[MS Transaction Server]
AutoRefresh
= 1
转载自 http://topic.csdn.net/t/20040508/00/3040090.html 自行调试通过
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值