可以声明窗口变量或变体变量 Dim frm [as Form] Set frm = New frmPeople frm.Show
If rs.State Then rs.Close strsql = "select Popedom from Tmp_UserPope Where UserName='aa' " rs.Open strsql, Cn, adOpenStatic, adLockReadOnly While Not rs.EOF For Each mycontrol In MDIFMain.Controls If mycontrol.Name = rs!Popedom Then mycontrol.Enabled = True Exit For End If Next rs.MoveNext Wend
这种要求简单的实现办法(如vfp那样)可能没有,至少我是没找到的。
online 的方法不错,但有局限性。 如果是没有加载的 form 或不是 mdi form ,for each 引用不到它。
Option Explicit Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As LongPublic Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean On Error Resume Next ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, Abs(fCheckOnly)) = 0 End FunctionPrivate Sub Command1_Click() On Error Resume Next ExecuteLine "dim i as long ,j as long", False ExecuteLine "i = 1:j=3", False ExecuteLine "msgbox i + j", False ExecuteLine "msgbox (1+2)*3/4", False ExecuteLine "dim a as string", False ExecuteLine "a = ""dd""", False ExecuteLine "msgbox a", False ExecuteLine "Form2.show" End Sub
if strFrm="Form2" then form2.show end if 大家不要打我
呵呵 谢谢大家的踊跃发表高论 小弟收益非浅,感激不尽 为了表示谢意,对大家讨论的一个肯定,我对有用的方法进行了一定的总结 大概有两种可用的方法: [[***************2004.7.8----jimy***********]] 方法一:(使用WinAPI方法) 1)引用API Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long 2)声明API函数 Private Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, Abs(fCheckOnly)) = 0 End Function 3)使用API函数实现字符串form的显示(进行简单的封装) Private Sub ShowForm(strFrm As String) Dim strTest As String strTest = "dim f as " & strFrm ExecuteLine strTest strTest = "set f=new " & strFrm ExecuteLine strTest strTest = "f.show " ExecuteLine strTest End Sub Private Sub Command1_Click() ShowForm "Form2" End Sub 4)其他命令的转化(注意带字符串参数的函数) Private Sub Command2_Click() ExecuteLine "dim i as long ,j as long", False ExecuteLine "i = 1:j=3", False ExecuteLine "msgbox i + j", False ExecuteLine "msgbox (1+2)*3/4", False ExecuteLine "dim a as string", False ExecuteLine "a = ""dd""", False ExecuteLine "msgbox a", False ExecuteLine "msgbox ""hello"",false" End Sub 注:它不会执行自定义的函数 如: ExecuteLine "ShowForm",false 'ShowForm为自定义函数方法二:(只能用户于显示form) 1)定义函数(用于显示form) Private Function ShowNamedForm(strForm As String) As Form Dim frmTemp As Form Set frmTemp = Forms.Add(strForm) frmTemp.Show Set ShowNamedForm = frmTemp End Function 2)使用 Private Sub Command3_Click() Dim frmtmp As Form Set frmtmp = ShowNamedForm("Form2") frmtmp.Caption = "hello" '更改frm的标题 End Sub 感:第一种方法是有些不错误,但是有些遗憾的是不能执行自定义的函数(在上面有说) 如能修改这点,那就太好了 在这里写个总结,是希望大家以后在提问题解决后,能够进行一定的总结,给以后的读者方便 谢谢大家
我现在是想实现数据启动功能
也就是所有的菜单等等对应的form都放到数据库中
没添加一个就设计相应的标志就可以了
所以用到这个功能
Dim frm [as Form]
Set frm = New frmPeople
frm.Show
strsql = "select Popedom from Tmp_UserPope Where UserName='aa' "
rs.Open strsql, Cn, adOpenStatic, adLockReadOnly
While Not rs.EOF
For Each mycontrol In MDIFMain.Controls
If mycontrol.Name = rs!Popedom Then
mycontrol.Enabled = True
Exit For
End If
Next rs.MoveNext
Wend
如果是没有加载的 form 或不是 mdi form ,for each 引用不到它。
Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As LongPublic Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean
On Error Resume Next
ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, Abs(fCheckOnly)) = 0
End FunctionPrivate Sub Command1_Click()
On Error Resume Next
ExecuteLine "dim i as long ,j as long", False
ExecuteLine "i = 1:j=3", False
ExecuteLine "msgbox i + j", False
ExecuteLine "msgbox (1+2)*3/4", False
ExecuteLine "dim a as string", False
ExecuteLine "a = ""dd""", False
ExecuteLine "msgbox a", False
ExecuteLine "Form2.show"
End Sub
form2.show
end if
大家不要打我
谢谢大家的踊跃发表高论
小弟收益非浅,感激不尽
为了表示谢意,对大家讨论的一个肯定,我对有用的方法进行了一定的总结
大概有两种可用的方法:
[[***************2004.7.8----jimy***********]]
方法一:(使用WinAPI方法)
1)引用API
Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long
2)声明API函数
Private Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean
ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
3)使用API函数实现字符串form的显示(进行简单的封装)
Private Sub ShowForm(strFrm As String)
Dim strTest As String
strTest = "dim f as " & strFrm
ExecuteLine strTest
strTest = "set f=new " & strFrm
ExecuteLine strTest
strTest = "f.show "
ExecuteLine strTest
End Sub
Private Sub Command1_Click()
ShowForm "Form2"
End Sub
4)其他命令的转化(注意带字符串参数的函数)
Private Sub Command2_Click()
ExecuteLine "dim i as long ,j as long", False
ExecuteLine "i = 1:j=3", False
ExecuteLine "msgbox i + j", False
ExecuteLine "msgbox (1+2)*3/4", False
ExecuteLine "dim a as string", False
ExecuteLine "a = ""dd""", False
ExecuteLine "msgbox a", False
ExecuteLine "msgbox ""hello"",false"
End Sub
注:它不会执行自定义的函数
如: ExecuteLine "ShowForm",false 'ShowForm为自定义函数方法二:(只能用户于显示form)
1)定义函数(用于显示form)
Private Function ShowNamedForm(strForm As String) As Form
Dim frmTemp As Form
Set frmTemp = Forms.Add(strForm)
frmTemp.Show
Set ShowNamedForm = frmTemp
End Function
2)使用
Private Sub Command3_Click()
Dim frmtmp As Form
Set frmtmp = ShowNamedForm("Form2")
frmtmp.Caption = "hello" '更改frm的标题
End Sub
感:第一种方法是有些不错误,但是有些遗憾的是不能执行自定义的函数(在上面有说)
如能修改这点,那就太好了
在这里写个总结,是希望大家以后在提问题解决后,能够进行一定的总结,给以后的读者方便
谢谢大家