📄 form1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
ClientHeight = 8295
ClientLeft = 60
ClientTop = 345
ClientWidth = 11880
LinkTopic = "Form1"
ScaleHeight = 8295
ScaleWidth = 11880
StartUpPosition = 3 '窗口缺省
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = "G:\liujing\vb\4.5\vb总结\原代码\第27章 数据库的特殊处理\简历例程\雇员简历.mdb"
DefaultCursorType= 0 '缺省游标
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 615
Left = 7440
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "test"
Top = 240
Width = 2055
End
Begin VB.CommandButton cmdAddResume
Caption = "添加简历"
Height = 495
Left = 4200
TabIndex = 7
Top = 0
Width = 1215
End
Begin VB.CommandButton cmdAddEmployee
Caption = "新建雇员"
Height = 495
Left = 2880
TabIndex = 6
Top = 0
Width = 1215
End
Begin VB.CommandButton cmdExit
Caption = "退出"
Height = 495
Left = 5520
TabIndex = 5
Top = 600
Width = 1215
End
Begin VB.TextBox txtID
DataField = "ID"
DataSource = "Data1"
Height = 375
Left = 720
TabIndex = 4
Top = 0
Width = 2055
End
Begin VB.TextBox txtName
DataField = "Name"
DataSource = "Data1"
Height = 375
Left = 720
TabIndex = 3
Top = 480
Width = 2055
End
Begin VB.CommandButton cmdSave
Caption = "保存"
Height = 495
Left = 5520
TabIndex = 2
Top = 0
Width = 1215
End
Begin VB.CommandButton cmdNext
Caption = "下一条"
Height = 495
Left = 4200
TabIndex = 1
Top = 600
Width = 1215
End
Begin VB.CommandButton cmdPre
Caption = "上一条"
Height = 495
Left = 2880
TabIndex = 0
Top = 600
Width = 1215
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 9600
Top = 720
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.OLE OLE1
Class = "Word.Document.8"
DataField = "Resume"
DataSource = "Data1"
Height = 6735
Left = 240
OleObjectBlob = "Form1.frx":0000
TabIndex = 11
Top = 1440
Width = 11535
End
Begin VB.Label Label1
Caption = "编号"
Height = 255
Left = 240
TabIndex = 10
Top = 120
Width = 615
End
Begin VB.Label Label2
Caption = "姓名"
Height = 255
Left = 240
TabIndex = 9
Top = 600
Width = 615
End
Begin VB.Label Label3
Caption = "简历"
Height = 255
Left = 240
TabIndex = 8
Top = 1080
Width = 495
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const OLE_SAVE_TO_FILE = 11 ' 'OLE Action 常 量
Const OLE_LOAD_FROM_FILE = 12 'OLE Action 常 量
Const CHUNK_SIZE = 32000 ' 文 件 读 写 块 的 大 小
Dim Filename As String
Private Sub cmdAddEmployee_Click() '添加新的雇员信息
Data1.Recordset.AddNew
End Sub
Private Sub cmdAddResume_Click() '添加简历
Dim iFileNumber As Integer
CommonDialog1.Filter = "word文档|*.doc"
CommonDialog1.ShowOpen
Filename = CommonDialog1.Filename
If Filename <> "" Then
iFileNumber = FreeFile
Open Filename For Binary Access Read As iFileNumber
Seek iFileNumber, 1
' 到 object 的 起 始 位 置
OLE1.FileNumber = iFileNumber
'OLE 控 件 指 向 临 时 文 件
OLE1.CreateEmbed Filename
OLE1.DoVerb -5
Close iFileNumber
End If
End Sub
Private Sub cmdExit_Click() '退出系统
End
End Sub
Private Sub cmdNext_Click() '下一条
If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
End If
End Sub
Private Sub cmdPre_Click() '上一条
If Not Data1.Recordset.BOF Then
Data1.Recordset.MovePrevious
End If
End Sub
Private Sub cmdSave_Click() '保存
Dim eError As Integer
Data1.Recordset("ID") = txtID.Text
Data1.Recordset("name") = txtName.Text
eError = OLEToField() '保存OLE控件OLE1中的内容
DoEvents
End Sub
Function OLEToField() As Integer '保存OLE控件中的内容
Dim eError As Integer
Dim iFileNumber As Integer
iFileNumber = FreeFile '获取文件号
Open App.Path & "\OLE.TMP" For Binary As iFileNumber '创建临时文件
OLE1.FileNumber = iFileNumber 'OLE控件指向临时文件
OLE1.Action = OLE_SAVE_TO_FILE '将字段的内容写到临时文件中
Seek iFileNumber, 1 '到Object的起始位置
Data1.Recordset("resume") = "" '清空OLE字段
eError = FileStreamToField(iFileNumber) '将文件写入OLE字段中
Close iFileNumber '关闭临时文件
Kill App.Path & "\OLE.TMP" '删除临时文件
OLEToField = 0 '返回
End Function
'下面的函数将临时文件写入数据库的OLE字段中
Function FileStreamToField(iFileNumber As Integer) As Integer
Dim sChunkHolder As String
Dim lChunkCount As Long
Dim lChunkRemainder As Long
Dim I As Long
sChunkHolder = Space$(CHUNK_SIZE) '临时存贮块
lChunkCount = (LOF(iFileNumber) - Seek(iFileNumber) + 1) \ CHUNK_SIZE '取块数
lChunkRemainder = (LOF(iFileNumber) - Seek(iFileNumber) + 1) Mod CHUNK_SIZE
'取整块后余下的数据
For I = 1 To lChunkCount
Get iFileNumber, , sChunkHolder '从文件中取出一块
Data1.Recordset("resume").AppendChunk (sChunkHolder) '将块写入字段中
Next
If lChunkRemainder > 0 Then
sChunkHolder = Space$(lChunkRemainder) '临时存贮块
Get iFileNumber, , sChunkHolder '取出该块
Data1.Recordset("resume").AppendChunk (sChunkHolder) '写入字段中
End If
FileStreamToField = 0 '返回
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -