PrintForm 方法
      
用以将 Form 对象的图象逐位发送给打印机。语法object.PrintFormobject 所在处代表一个对象表达式,其值为“应用于”列表中的一个对象。如果省略 object,则带有焦点的 Form 对象缺省为 object。说明PrintForm 将打印 Form 对象的全部可见对象和位图。在绘制图形时,如果 AutoRedraw 属性为 True,则在运行时PrintForm 将打印 Form 对象或 PictureBox 控件上的图形。PrintForm 所使用的打印机是由操作系统的控制面板中的设置来决定。PrintForm 方法示例 
本示例使用 PrintForm 方法打印当前窗体。要检验此示例,可将本例代码粘贴到一个窗体的声明部分。在窗体上放置任何在打印出来的窗体上想要看到的控件,然后按 F5 键并单击该窗体。Private Sub Form_Click ()
   Dim Msg   ' 声明变量。
   On Error GoTo ErrorHandler   ' 设置错误处理程序。
   PrintForm   ' 打印窗体。
   Exit Sub
ErrorHandler:
   Msg = "The form can't be printed."
   MsgBox Msg   ' 显示信息。
   Resume Next
End Sub

解决方案 »

  1.   

    做一个excel的模板,直接打印它就可以了。
      

  2.   

    要vb程序吊的,你的datagrid具体是什么样的?
      

  3.   

    打印窗体不太现实,如果datagrid的记录超出了它的滚动条,它是不会显示的。你可以添加一个‘数据环境设计器’和一个‘报表窗体’,在数据环境设计器中,为sql语句设置一个参数,然后把字段拖放到报表设计器中。在打印的时候,把某一个字段的值,如“姓名”传递给数据环境的sql语句。这样打印出的记录就是你的sql语句查询出的结果.
      

  4.   

    Option Explicit
    Private Sub Command1_Click()
    Dim I As Long, J As Long, K As Long
    Dim PrintString As String
    For I = 0 To Data1.Recordset.RecordCount - 1
    If K = DBGrid1.VisibleRows Then
    DBGrid1.Scroll 0, DBGrid1.VisibleRows
    K = 0
    End If
    For J = 0 To DBGrid1.Columns.Count - 1
    PrintString = PrintString &
    DBGrid1.Columns(J).CellText(DBGrid1.RowBook(K)) & "/"
    Next
    Printer.Print PrintString
    PrintString = ""
    K = K + 1
    DoEvents
    Next
    End SubPrivate Sub Form_Activate()
    Data1.Recordset.MoveLast
    Data1.Recordset.MoveFirst
    End Sub
      

  5.   

    http://www.triaton.com.cn/Private/Zip/DatGrdRpt.ziphttp://www.triaton.com.cn/Private/Zip/BarCodeRpt.zip
    http://www.triaton.com.cn/Private/Zip/DatRpt.zip
    http://www.triaton.com.cn/Private/Zip/FmtDatRpt.zip
    http://www.triaton.com.cn/Private/Zip/ShapeNew.zip
    http://www.triaton.com.cn/Private/Zip/ShapeTree.zip《vb 6之数据报表使用技巧》
    http://media.ccidnet.com/media/ciw/871/b1301.htm
      

  6.   

    Public rowlab As Integer
    Function prntl(x As Integer, y As Integer, font As Single, txt As String, val As Integer)
      Dim str As String, i As Integer, str2 As String
      Printer.CurrentX = x
      Printer.CurrentY = y
      Printer.FontBold = False
      Printer.FontSize = font
      str = txt
      str2 = str
      i = 0
      rowlab = 0
      If Len(Trim(str)) = 0 Then
        rowlab = 1
      Else
        Do While Len(str) > 0
          Printer.CurrentX = x
          Printer.CurrentY = y + rowlab * 240
          rowlab = rowlab + 1
          If Len(str) >= val Then
            str1 = Mid(str, 1, val)
            Printer.Print str1
            i = i + 1
            str = Mid(str2, i * val + 1)
          Else
            Printer.Print str
            Exit Do
          End If
        Loop
      End If
    End Function
      

  7.   

    http://www.triaton.com.cn/Private/Zip/DatGrdRpt.zip
      

  8.   

    我的数据库用的是SQL,不是ACCESS,请问我该怎么办?