set datareport1.datasource=rst(记录集) 或者 set datareport1.datasource=adodc1.recordset(记录集)
datareport1是一个控件吧,不是datagrid控件吧,这样就能够实现打印?
这是我某程序中打印的一部分.参考一下.(针对MSHFLEXGRID的,你可以改一下,让它适用RS即可.Sub PrintA(PS As Long, PE As Long) '打印成绩表 Dim a As Long Dim B As Long Dim GColWidth As Long Dim GRowHighe As Long Dim LineX As Long Dim LineY As Long Dim DltP As Long Dim PrintR As Long Dim FixLab As String Dim TmpWidth As Long Dim DltH As Long Dim PageStar As Long Dim PageEnd As Long '------------------------------------------------ ProwStar = 6: PageWidth = 0 PrintGrid.Cols = PColMax - 1
LineX = LineX + TmpWidth If a = 0 And B = PrintGrid.Cols - 1 Then Printer.Line (LineX, GridTop)-(LineX, GridTop + PageHeight) End If Next B LineY = LineY + RowHei '画最后一条线 If a = PrintGrid.Rows - 1 Then Printer.Line (GridLeft, LineY)-(GridLeft + PageWidth, LineY) End If Next a Label1 = "第" & PageStar & "页" If GridLeft + PrintGrid.Width > PrintPic.Width - 1200 Then Label1.Left = PrintPic.Width - 1200 Else Label1.Left = GridLeft + PrintGrid.Width - Label1.Width End If Printer.CurrentX = Label1.Left Printer.CurrentY = LineY + 210 Printer.Print Label1 DoEvents If PageStar < PE Then Printer.NewPage Else Printer.EndDoc End If Next PageStar End Sub
private sub cmdbutton1_click() Set DataReport1.DataSource = rs DataReport1.show end subPrivate Sub DataReport_Initialize() AddDetailReport.Sections("section1").Controls("text1").DataField = form1.rs(0).name AddDetailReport.Sections("section1").Controls("text2").DataField = form1.rs(1).name ....... 'section1为datareport中的细节栏 'text1,text2是细节中的 RptTextbox控件 End Sub
to Tarzen(大冠): Private Sub DataReport_Initialize() AddDetailReport.Sections("section1").Controls("text1").DataField = form1.rs(0).name ‘他说add有问题’ AddDetailReport.Sections("section1").Controls("text2").DataField = form1.rs(1).name ....... 'section1为datareport中的细节栏 'text1,text2是细节中的 RptTextbox控件 End Sub 这个函数有问题
谁能说得具体点,我没用个datareport
我写错了,AddDetailReport 是上面所指的那个DataReport1,你可以把它该过来 rs是RecordSet,我想你应该已经产生了一个;如过没有的话也可以生成一个 private sub cmdbutton1_click() dim conn as new Adodb.connection dim rs as new Adodb.RecordSet dim connstr as string connstr="provider=... data source=...." conn.open connstr dim sql as string sql="select * from ... where..." set rs=conn.execute(sql) Set DataReport1.DataSource = rs DataReport1.show end sub 还有你必须先创建dataReport1并在Section1中放text1 and text2
Private Sub DataReport_Initialize()这不是什么函数,这是dataReport的初使化过程, 双击datareport 就可进入 从vb 的project-》Add Datareport向你的program中加入datareport
或者
set datareport1.datasource=adodc1.recordset(记录集)
这是我某程序中打印的一部分.参考一下.(针对MSHFLEXGRID的,你可以改一下,让它适用RS即可.Sub PrintA(PS As Long, PE As Long) '打印成绩表
Dim a As Long
Dim B As Long
Dim GColWidth As Long
Dim GRowHighe As Long
Dim LineX As Long
Dim LineY As Long
Dim DltP As Long
Dim PrintR As Long
Dim FixLab As String
Dim TmpWidth As Long
Dim DltH As Long
Dim PageStar As Long
Dim PageEnd As Long
'------------------------------------------------
ProwStar = 6: PageWidth = 0
PrintGrid.Cols = PColMax - 1
PrintGrid.RowHeight(-1) = RowHei
PrintGrid.Font.Name = MainFrm.MainGrid.Font.Name
PrintGrid.Font.Size = MainFrm.MainGrid.Font.Size
GridLeft = PrintGrid.Left - 0.5 * 567: GridTop = PrintGrid.Top
DltP = PRowMax - 1
For PageStar = PS To PE
PrintR = (PRowMax - 1) * (PageStar - 1)
For a = 1 To PrintGrid.Rows - 1
For B = 0 To PColMax - 2
If (PrintR + a + 5) < MainFrm.MainGrid.Rows Then
PrintGrid.TextMatrix(a, B) = MainFrm.MainGrid.TextMatrix(PrintR + a + 5, B + 1)
Else
PrintGrid.TextMatrix(a, B) = ""
End If
Next B
Next a
'开始打印
Printer.Font.Name = PrintGrid.Font.Name
Printer.Font.Size = PrintGrid.Font.Size
Printer.ScaleTop = 0: Printer.ScaleLeft = 0
Printer.ScaleWidth = Printer.Width + 567
Printer.ScaleHeight = Printer.Height
GridTop = PrintGrid.Top: GridLeft = PrintGrid.Left - 0.5 * 567
LenLab.FontName = PrintGrid.Font.Name
LenLab.Font.Size = PrintGrid.Font.Size
DltH = (RowHei - LenLab.Height) \ 2
'-----------------------------------------------------------------
PageWidth = PrintGrid.Width
LineY = GridTop
For a = 0 To PrintGrid.Rows - 1
LineX = GridLeft
'画横线
Printer.Line (GridLeft, LineY)-(GridLeft + PageWidth, LineY)
For B = 0 To PrintGrid.Cols - 1
TmpWidth = PrintGrid.ColWidth(B)
If a = 0 Then
'输出表头,并画竖线
FixLab = PrintGrid.TextMatrix(0, B)
LenLab = FixLab: DoEvents
Printer.Line (LineX, GridTop)-(LineX, GridTop + PageHeight)
Printer.CurrentX = LineX + (TmpWidth - LenLab.Width) \ 2
Printer.CurrentY = LineY + DltH
Printer.Print FixLab
Else
'输出内容
Printer.CurrentX = LineX + 45
Printer.CurrentY = LineY + DltH
Printer.Print PrintGrid.TextMatrix(a, B)
End If
LineX = LineX + TmpWidth
If a = 0 And B = PrintGrid.Cols - 1 Then
Printer.Line (LineX, GridTop)-(LineX, GridTop + PageHeight)
End If
Next B
LineY = LineY + RowHei
'画最后一条线
If a = PrintGrid.Rows - 1 Then
Printer.Line (GridLeft, LineY)-(GridLeft + PageWidth, LineY)
End If
Next a
Label1 = "第" & PageStar & "页"
If GridLeft + PrintGrid.Width > PrintPic.Width - 1200 Then
Label1.Left = PrintPic.Width - 1200
Else
Label1.Left = GridLeft + PrintGrid.Width - Label1.Width
End If
Printer.CurrentX = Label1.Left
Printer.CurrentY = LineY + 210
Printer.Print Label1
DoEvents
If PageStar < PE Then
Printer.NewPage
Else
Printer.EndDoc
End If
Next PageStar
End Sub
Set DataReport1.DataSource = rs
DataReport1.show
end subPrivate Sub DataReport_Initialize()
AddDetailReport.Sections("section1").Controls("text1").DataField =
form1.rs(0).name
AddDetailReport.Sections("section1").Controls("text2").DataField =
form1.rs(1).name
.......
'section1为datareport中的细节栏
'text1,text2是细节中的 RptTextbox控件
End Sub
Private Sub DataReport_Initialize()
AddDetailReport.Sections("section1").Controls("text1").DataField =
form1.rs(0).name ‘他说add有问题’
AddDetailReport.Sections("section1").Controls("text2").DataField =
form1.rs(1).name
.......
'section1为datareport中的细节栏
'text1,text2是细节中的 RptTextbox控件
End Sub
这个函数有问题
rs是RecordSet,我想你应该已经产生了一个;如过没有的话也可以生成一个
private sub cmdbutton1_click()
dim conn as new Adodb.connection
dim rs as new Adodb.RecordSet
dim connstr as string
connstr="provider=... data source=...."
conn.open connstr
dim sql as string
sql="select * from ... where..."
set rs=conn.execute(sql)
Set DataReport1.DataSource = rs
DataReport1.show end sub
还有你必须先创建dataReport1并在Section1中放text1 and text2
双击datareport 就可进入
从vb 的project-》Add Datareport向你的program中加入datareport