日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

VB 把數(shù)據(jù)庫導(dǎo)出給word

 jztgwq 2012-12-31
 

Dim ws As Workspace, db As Database, tb As TableDef, rs As Recordset
Dim nn As Long, errS As String
Dim Errstring As String
Private Sub Form_Load()
  Data1.DatabaseName = App.Path & "\db.mdb"
  Text1.Text = Data1.DatabaseName
End Sub
Private Sub Command3_Click()
  Dim filen As String, dirf As String, mm As String
  mm = ""
  Errstring = "這個(gè)數(shù)據(jù)庫已加密,請(qǐng)輸入密碼:"
  Comm1.FileName = "*.mdb;*.dbf"
  Comm1.Filter = "*.mdb"
  Comm1.DialogTitle = "打開數(shù)據(jù)庫文件"
  Comm1.ShowOpen
  filen = LCase(Comm1.FileName)
  For i = Len(filen) To 1 Step -1
      dirf = Mid(filen, i, 1)
      If dirf = "\" Then
         dirf = Left(filen, i)
         Exit For
      End If
  Next
  If filen <> "*.mdb;*.dbf" Then
     List1.Clear
     Set ws = DBEngine.Workspaces(0)
     If Right(filen, 3) = "mdb" Then
        Set db = ws.OpenDatabase(filen, False, False, ";pwd=" & mm)
      Else
        Set db = ws.OpenDatabase(dirf, False, False, "FoxPro 2.6")
     End If
  End If
  For Each tb In db.TableDefs
     If Left(tb.Name, 4) <> "MSys" Then List1.AddItem (tb.Name)
  Next
  List1.Refresh
  Text1.Text = Comm1.FileName
End Sub
Private Sub Command1_Click()
  Dim i As Integer, j As Integer
  Dim ifieldcount As Integer, irecordcount As Integer
  Dim wdapp As Word.Application
  Dim wddoc As Word.Document
  Dim atable As Word.Table
  With Data1.Recordset
       Data1.Recordset.MoveLast
       Data1.Recordset.MoveFirst
       ifieldcount = .Fields.Count
       irecordcount = .RecordCount
  End With
  On Error Resume Next
  '創(chuàng)建word應(yīng)用程序,這一句話打開word2000
  Set wdapp = CreateObject("Word.Application")
  '在word中添加一個(gè)新文檔
  Set wddoc = wdapp.Documents.Add
  With wdapp
  .Visible = True
  .Activate
  '在word中增加一個(gè)表格
  Set atable = .ActiveDocument.Tables.Add(.Selection.Range, irecordcount + 1, ifieldcount)
  For i = 0 To ifieldcount - 1
      atable.Cell(1, i + 1).Range.InsertAfter DBGrid1.Columns(i)
  Next i
  '指定表格內(nèi)容
  For i = 0 To irecordcount - 1
  For j = 0 To ifieldcount - 1
      DBGrid1.Row = i
      DBGrid1.Col = j
      atable.Cell(i + 2, j + 1).Range.InsertAfter DBGrid1.Text
  Next j
  Next i
  End With
  '清除word對(duì)象
  Set wdapp = Nothing
  Set wddoc = Nothing
End Sub

Private Sub List1_Click()
  Data1.DatabaseName = Text1.Text
  Data1.RecordSource = List1.Text
  Data1.Refresh
  DBGrid1.Refresh
End Sub
Private Sub Command2_Click()
  End
End Sub

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多