设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12下一页
返回列表 发新帖
查看: 3733|回复: 10
打印 上一主题 下一主题

[窗体] (已解决)请问,如何在函数中用代码来引用一个未知的窗体,急!!

[复制链接]
跳转到指定楼层
1#
发表于 2008-2-2 16:41:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请问,如何在函数中用代码来引用一个未知的窗体,以便对这个窗体的控件属性进行定义。

[ 本帖最后由 dreamice01 于 2008-2-27 09:40 编辑 ]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2008-2-2 16:48:11 | 只看该作者
未知窗体?不明白是什么。。。。
3#
 楼主| 发表于 2008-2-2 16:49:35 | 只看该作者

回复 2# 的帖子

就是要调用这个函数的窗体,但调用函数的窗体在函数中是未知的,是一个需要传递的参数

像这种窗体的调用,代码怎么写?
4#
发表于 2008-2-2 17:01:24 | 只看该作者
函数在声明时先定义一个窗体变量, 编写时以此变量作为窗体名

function test(Frm as form)
5#
 楼主| 发表于 2008-2-2 17:22:03 | 只看该作者

回复 4# 的帖子

那引用这个函数可以这样引用吗?

test  窗体名
但我做完后调试怎么报错?提示:参数类型不符

这个是怎么用来着,谢谢!
6#
发表于 2008-2-2 17:31:12 | 只看该作者
把你完整的函数贴上来
7#
 楼主| 发表于 2008-2-2 17:45:03 | 只看该作者
在窗体中引用数据导出函数
Private Sub cmd_export_qichu_Click()
Dim frm As Object
set frm = revenue_cost_data_import    '将窗体名赋值给变量
On Error GoTo err_cmd_export_qichu
    exportExportData frm,straction, "期初分摊率基础数据模板"   
exit_cmd_export_qichu:
  Exit Sub
err_cmd_export_qichu:
   MsgBox Err.Description
   Resume exit_cmd_export_qichu
End Sub

'在数据导出函数中引用另一个进度条函数
Public Function exportExportData(frm as form,straction As String, _
  Optional strObject As String = "", Optional intType As Integer) As Boolean
Dim Conn As ADODB.Connection
Dim Rs As ADODB.Recordset
Set Conn = CurrentProject.Connection
Set Rs = CreateObject("ADODB.Recordset")

Rs.Open straction, Conn, 1
FunProGressBar frm, 0, Rs.RecordCount
' Called from ImportExport form
On Error GoTo HandleErr
    ' Turn off screen updating
    Application.Echo False
    ' If we're exporting, open the object
    DoCmd.OpenTable strObject, acViewNormal
    ' Kick off the action the user has chosen
    DoCmd.RunCommand acCmdOutputToExcel
    DoCmd.Close
    exportExportData = True
ExitHere:
    Application.Echo True
    Exit Function
HandleErr:
    exportExportData = False
    Select Case Err
        Case 2501       ' User cancelled
            Resume ExitHere
        Case Else
            MsgBox Err & ": " & Err.Description & "错误发生在数据导出函数", vbOKOnly + vbCritical, "系统提示"
            Resume ExitHere
    End Select
End Function
'在这个进度条函数中需要对窗体中的一些控制的属性赋值
Public Function FunProGressBar(frm As Form, ByVal RecValue, ByVal RecMax, Optional TempText As String)
'    Dim TempProWidth As Integer ' ''进度条总长
Dim Temptimes As Long      ''进度时间
Dim TempCounttime As Double   ''时间总长度
Dim ShowTimes As String       ''显示的时间,以分;秒结束
Const TempProWidth = 5790     ''进度条总长
On Error GoTo Err:
If RecValue = 1 Then TempTimeon = Now
If RecValue > RecMax Then Exit Function
DoEvents
With frm
  .proportion.Caption = Round(RecValue / RecMax, 2) * 100 & "%"
  .TempText.Caption = "分析"
  .Temptimes = DateDiff("s", TempTimeon, Now) / RecValue * (RecMax - RecValue)
  If RecValue > 1 Then .RunTime.Caption = "大约剩余 " & ShowTimes
If RecValue = RecMax Then .TempCounttime = DateDiff("s", TempTimeon, Now)
End With
End Function
8#
 楼主| 发表于 2008-2-2 17:45:46 | 只看该作者
在窗体中引用数据导出函数
Private Sub cmd_export_qichu_Click()
Dim frm As Object
set frm = revenue_cost_data_import    '将窗体名赋值给变量
On Error GoTo err_cmd_export_qichu
    exportExportData frm,straction, "期初分摊率基础数据模板"   
exit_cmd_export_qichu:
  Exit Sub
err_cmd_export_qichu:
   MsgBox Err.Description
   Resume exit_cmd_export_qichu
End Sub

'在数据导出函数中引用另一个进度条函数
Public Function exportExportData(frm as form,straction As String, _
  Optional strObject As String = "", Optional intType As Integer) As Boolean
Dim Conn As ADODB.Connection
Dim Rs As ADODB.Recordset
Set Conn = CurrentProject.Connection
Set Rs = CreateObject("ADODB.Recordset")

Rs.Open straction, Conn, 1
FunProGressBar frm, 0, Rs.RecordCount
' Called from ImportExport form
On Error GoTo HandleErr
    ' Turn off screen updating
    Application.Echo False
    ' If we're exporting, open the object
    DoCmd.OpenTable strObject, acViewNormal
    ' Kick off the action the user has chosen
    DoCmd.RunCommand acCmdOutputToExcel
    DoCmd.Close
    exportExportData = True
ExitHere:
    Application.Echo True
    Exit Function
HandleErr:
    exportExportData = False
    Select Case Err
        Case 2501       ' User cancelled
            Resume ExitHere
        Case Else
            MsgBox Err & ": " & Err.Description & "错误发生在数据导出函数", vbOKOnly + vbCritical, "系统提示"
            Resume ExitHere
    End Select
End Function
'在这个进度条函数中需要对窗体中的一些控制的属性赋值
Public Function FunProGressBar(frm As Form, ByVal RecValue, ByVal RecMax, Optional TempText As String)
'    Dim TempProWidth As Integer ' ''进度条总长
Dim Temptimes As Long      ''进度时间
Dim TempCounttime As Double   ''时间总长度
Dim ShowTimes As String       ''显示的时间,以分;秒结束
Const TempProWidth = 5790     ''进度条总长
On Error GoTo Err:
If RecValue = 1 Then TempTimeon = Now
If RecValue > RecMax Then Exit Function
DoEvents
With frm
  .proportion.Caption = Round(RecValue / RecMax, 2) * 100 & "%"
  .TempText.Caption = "分析"
  .Temptimes = DateDiff("s", TempTimeon, Now) / RecValue * (RecMax - RecValue)
  If RecValue > 1 Then .RunTime.Caption = "大约剩余 " & ShowTimes
If RecValue = RecMax Then .TempCounttime = DateDiff("s", TempTimeon, Now)
End With
End Function
9#
 楼主| 发表于 2008-2-2 17:46:42 | 只看该作者

回复 6# 的帖子

不好意思,网络不太好,以为没发过来,发了两次,麻烦你帮我改一下,谢谢!
10#
发表于 2008-2-2 17:49:32 | 只看该作者
先打开窗体,再进行定义
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-17 04:44 , Processed in 0.092069 second(s), 33 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表