⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 从EXCLE表中把对应的数据导入到ACCESS数据库中。
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   7455
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   11040
   LinkTopic       =   "Form1"
   ScaleHeight     =   7455
   ScaleWidth      =   11040
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text1 
      Height          =   495
      Left            =   5220
      TabIndex        =   17
      Text            =   "Text1"
      Top             =   120
      Width           =   2235
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   345
      Left            =   2100
      Top             =   6360
      Width           =   3255
      _ExtentX        =   5741
      _ExtentY        =   609
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   525
      Left            =   6930
      TabIndex        =   16
      Top             =   2370
      Width           =   2685
   End
   Begin VB.TextBox Txtxing 
      Height          =   495
      Index           =   7
      Left            =   2310
      TabIndex        =   7
      Text            =   "7"
      Top             =   4470
      Width           =   2295
   End
   Begin VB.TextBox Txtxing 
      Height          =   495
      Index           =   6
      Left            =   2310
      TabIndex        =   6
      Text            =   "6"
      Top             =   3852
      Width           =   2295
   End
   Begin VB.TextBox Txtxing 
      Height          =   495
      Index           =   5
      Left            =   2310
      TabIndex        =   5
      Text            =   "5"
      Top             =   3235
      Width           =   2295
   End
   Begin VB.TextBox Txtxing 
      Height          =   495
      Index           =   4
      Left            =   2310
      TabIndex        =   4
      Text            =   "4"
      Top             =   2618
      Width           =   2295
   End
   Begin VB.TextBox Txtxing 
      Height          =   495
      Index           =   3
      Left            =   2310
      TabIndex        =   3
      Text            =   "3"
      Top             =   2001
      Width           =   2295
   End
   Begin VB.TextBox Txtxing 
      Height          =   495
      Index           =   2
      Left            =   2310
      TabIndex        =   2
      Text            =   "2"
      Top             =   1384
      Width           =   2295
   End
   Begin VB.TextBox Txtxing 
      Height          =   495
      Index           =   1
      Left            =   2310
      TabIndex        =   1
      Text            =   "1"
      Top             =   767
      Width           =   2295
   End
   Begin VB.TextBox Txtxing 
      Height          =   495
      Index           =   0
      Left            =   2310
      TabIndex        =   0
      Text            =   "0"
      Top             =   150
      Width           =   2295
   End
   Begin VB.Label Lbxing 
      Caption         =   "地址"
      Height          =   375
      Index           =   7
      Left            =   870
      TabIndex        =   15
      Top             =   2070
      Width           =   1335
   End
   Begin VB.Label Lbxing 
      Caption         =   "是否体检"
      Height          =   375
      Index           =   6
      Left            =   840
      TabIndex        =   14
      Top             =   4545
      Width           =   1335
   End
   Begin VB.Label Lbxing 
      Caption         =   "活动地点"
      Height          =   375
      Index           =   5
      Left            =   840
      TabIndex        =   13
      Top             =   3930
      Width           =   1335
   End
   Begin VB.Label Lbxing 
      Caption         =   "联系电话"
      Height          =   375
      Index           =   4
      Left            =   840
      TabIndex        =   12
      Top             =   3315
      Width           =   1335
   End
   Begin VB.Label Lbxing 
      Caption         =   "预约时间"
      Height          =   375
      Index           =   3
      Left            =   810
      TabIndex        =   11
      Top             =   2700
      Width           =   1335
   End
   Begin VB.Label Lbxing 
      Caption         =   "年龄"
      Height          =   375
      Index           =   2
      Left            =   840
      TabIndex        =   10
      Top             =   1470
      Width           =   1335
   End
   Begin VB.Label Lbxing 
      Caption         =   "性别"
      Height          =   375
      Index           =   1
      Left            =   840
      TabIndex        =   9
      Top             =   855
      Width           =   1335
   End
   Begin VB.Label Lbxing 
      Caption         =   "姓名"
      Height          =   375
      Index           =   0
      Left            =   840
      TabIndex        =   8
      Top             =   240
      Width           =   1335
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim strdt As String
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open("E:\aatijian\shuju") '打开已经存在的EXCEL工件簿文件
xlApp.Visible = True '设置EXCEL对象可见(或不可见)
Set xlSheet = xlBook.Worksheets("sheet1") '设置活动工作表


'读取EXCEL表内容
Dim xlrow As Long
For xlrow = 1 To 5000
Txtxing(0).Text = xlSheet.Cells(xlrow, 1) '给单元格(row,col)赋值
Txtxing(1).Text = xlSheet.Cells(xlrow, 2)
Txtxing(2).Text = xlSheet.Cells(xlrow, 3)
Txtxing(3).Text = xlSheet.Cells(xlrow, 4)
Txtxing(4).Text = xlSheet.Cells(xlrow, 5)
Txtxing(5).Text = xlSheet.Cells(xlrow, 6)
Txtxing(6).Text = xlSheet.Cells(xlrow, 7)
Txtxing(7).Text = xlSheet.Cells(xlrow, 8)

If Txtxing(0).Text = "" Then GoTo ttt1:
'写入数据库
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("IDSN") = "TJ" & Format(Date, "yymmdd") & Adodc1.Recordset.RecordCount
Adodc1.Recordset.Fields("name") = Txtxing(0).Text
Adodc1.Recordset.Fields("sex") = Txtxing(1).Text
Adodc1.Recordset.Fields("eag") = Txtxing(2).Text
Adodc1.Recordset.Fields("dianhua") = Txtxing(5).Text
Adodc1.Recordset.Fields("fenqu") = Txtxing(6).Text
Adodc1.Recordset.Fields("dizhi") = Txtxing(3).Text
Adodc1.Recordset.Fields("lurudate") = Date

If Txtxing(4).Text <> "" Then
Adodc1.Recordset.Fields("yuyuedate") = Txtxing(4).Text
End If
If Txtxing(7).Text = "是" Then
Adodc1.Recordset.Fields("yuyue") = True
Else
Adodc1.Recordset.Fields("yuyue") = False
End If
Adodc1.Recordset.UpdateBatch
Adodc1.Refresh
Next xlrow




ttt1:
xlBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象
Set xlApp = Nothing '释放xlApp对象

End Sub

Private Sub Form_Load()
strdt = "Provider=Microsoft.Jet.OLEDB.4.0;" _
                            & "Data Source=" & App.Path & "\tijiandata.mdb;" _
                            & "Persist Security Info=False"
With Adodc1
.ConnectionString = strdt
.RecordSource = "select * from datatijian "
.Refresh
End With

End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -