我在一个窗口(1窗口)里用Dtreport.Show vbModal调用一个数据报表窗口(2窗口)
而2窗口里的代码
If Printer.Width <= reportwidth Or Printer.Width - reportwidth <= 1600 Then
MsgBox "报表宽度大于打印纸宽度", vbOKOnly, "提示"
' Unload Me
frmrpt.Show
Exit Sub
end if
我想让他停止加载报表窗口
可是用Unload Me的话在Dtreport.Show vbModal处报错对象变量或with块变量未设置
不用他的话就打开一个白板数据报窗口还说 未找到数据域datafield'(空)'请大虾指点下,该怎么弄啊 ???
而2窗口里的代码
If Printer.Width <= reportwidth Or Printer.Width - reportwidth <= 1600 Then
MsgBox "报表宽度大于打印纸宽度", vbOKOnly, "提示"
' Unload Me
frmrpt.Show
Exit Sub
end if
我想让他停止加载报表窗口
可是用Unload Me的话在Dtreport.Show vbModal处报错对象变量或with块变量未设置
不用他的话就打开一个白板数据报窗口还说 未找到数据域datafield'(空)'请大虾指点下,该怎么弄啊 ???
估计你其它代码还有问题,把窗口2的相关代码都贴出来看看吧。
Dim leftpos As Long 'leftpos为存放控件left属性的变量
Dim reportwidth As Long 'reportwidth为存放Datareport总宽度的变量
Dim reportwidth1 As Long
'Dim lst_selected As ListBox
Dim i As Integer
Dim j As Integer
Dim k As Integer
If frmrpt.lst_selected.ListCount <> 0 Then
'Call frmrpt.fieldwidth(frmrpt.lst_selected) '设置字段宽度
Const wordwidth As Integer = 201 '五号字的宽度为201缇
For i = 0 To frmrpt.lst_selected.ListCount - 1
Select Case frmrpt.lst_selected.List(i)
Case "学号"
frmrpt.lst_selected.ItemData(i) = wordwidth * 5
Case "姓名"
.......
End Select
Next i
'求总宽度
For i = 0 To frmrpt.lst_selected.ListCount - 1
reportwidth = reportwidth + frmrpt.lst_selected.ItemData(i)Next
'初始化
With Dtreport
'设置数据源,页边距,标题,横向分割线,section1、2区第一条竖分割线
.LeftMargin = 0
.RightMargin = 0
.TopMargin = 1440
.BottomMargin = 1000
'reportwidth1 = Printer.Width - .LeftMargin
.reportwidth = Printer.Width - 1000 - 20
Dim strSQL As String Set rs = ExecuteSQL(qtcxr.txSQL, MsgText)
'rs.Open strSQL, AdoCon
Set .DataSource = rsDtreport.Sections.Item("section2").Controls.Item("Label41").Caption = frmrpt.txt_caption
If Printer.Width <= reportwidth Or Printer.Width - reportwidth <= 1600 Then
MsgBox "报表宽度大于打印纸宽度", vbOKOnly, "提示"
' Unload Me
Call DataReport_Activate
frmrpt.Show
Exit Sub
End If
Dtreport.Sections.Item("section2").Controls.Item("Label41").Left = (Printer.Width - reportwidth) / 2 - 800
Dtreport.Sections("section2").Controls.Item("Label41").Width = reportwidth
......
End With'为section1,2区设置数据
leftpos = (Printer.Width - reportwidth) / 2 - 800For i = 0 To frmrpt.lst_selected.ListCount - 1
k = i - 1
Me.Sections("section2").Controls.Item("Label2" & (i + 1)).Caption = frmrpt.lst_selected.List(i)
Me.Sections("section2").Controls.Item("Label2" & (i + 1)).Width = frmrpt.lst_selected.ItemData(i)
Me.Sections("section1").Controls.Item("Text1" & (i + 1)).Width = frmrpt.lst_selected.ItemData(i)
If leftpos <= wordwidth * 5 Then
MsgBox "报表宽度大于打印纸宽度", vbOKOnly, "提示"
'Unload Me
Exit Sub
Unload Me
Load frmrpt
End If
Me.Sections("section1").Controls.Item("Text1" & (i + 1)).Left = leftpos - wordwidth * 5
GoTo Label1
End If
Next jLabel1:
'Me.Sections("section1").Controls.Item("Text1" & (i + 1)).DataField = rs.Fields.Item(i).NameNext i'对不用的text控件必须设置其datafield属性,如frmrpt.lst_selected.List(0),否则出错,但一定让其不可见
'其他不用的label,line控件同样均不可见
i = frmrpt.lst_selected.ListCount
While i < (Me.Sections("section1").Controls.Count - 19)
'10 为section1区域的非text控件的控件总数
i = i + 1
Me.Sections("section1").Controls.Item("Text1" & i).DataField = rs.Fields.Item(0).Name
Wend
End If
'Me.PrintReport True
End Sub
出现无效数据源的问题了
-----------------
这个原因是因为你下面的语句有BUG:
Set rs = ExecuteSQL(qtcxr.txSQL, MsgText)
'rs.Open strSQL, AdoCon
Set .DataSource = rs你这样修改一下:Set rs = ExecuteSQL(qtcxr.txSQL, MsgText)If not rs is nothing Then with Dtreport
Set .DataSource = rs
.....
End With .....End if
是直接跳出一个消息框来告诉无效数据源
如果把代码放在Initialize里就没这个错误
是可以通过的
Dim strAppPath As String
strAppPath = App.Path
If Right(strAppPath, 1) <> "\" Then
strAppPath = strAppPath & "\"
End If
strAppPath = App.Path & "\贫困生档案.mdb"
Dim AdoCon As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
Set AdoCon = New ADODB.Connection
AdoCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & strAppPath & ""
AdoCon.Open
strSQL = "select 学号,姓名 from 学生基本信息 "
Set rs = ExecuteSQL(strSQL, MsgText)
rs.Open strSQL, AdoCon
Set .DataSource = rs
Load Dtreport
Dtreport.show vbmodal
在这报错“找不到方法Fields”
你在Dtreport报表内定义一个变量dim m_Rst As ADODB.RecordSet在Initialize事件中加入如下代码:set m_Rst=Me.DataSource然后把Dtreport里的rs都换成m_Rst
这句有问题,运行过程中我把鼠标放上去
有提示“Dtreport.DataSource = nothing”
Set rs = ExecuteSQL(qtcxr.txSQL, MsgText)
没错,是正常的