

主要功能代码预览:
' 定义公共变量Public gctlInputCommonuseCalled As Control '调用窗体的控件Public gintCtlCalledSelStart As Integer '当前光标位置Public gintCtlCalledSellength As Integer '选取文本长度
'打开高频词选区窗体Public Function gInputCommonUseString() As String On Error Resume Next
Const cstrFormName = "frmpubselectIncommonuse" Const cstrCtlName = "list0"
If Not CurrentProject.AllForms(cstrFormName).IsLoaded Then '如果窗体是关闭的,那么打开窗体 Set gctlInputCommonuseCalled = Screen.ActiveControl '获取当前控件 If gctlInputCommonuseCalled Is Nothing Then Exit Function Else '写入相关属性到变量 gintCtlCalledSelStart = gctlInputCommonuseCalled.SelStart gintCtlCalledSellength = gctlInputCommonuseCalled.SelLength '保存修改,否则可能插入错误值(就是控件的旧值) DoCmd.RunCommand acCmdSaveRecord '打开窗体 DoCmd.OpenForm cstrFormName End If Else '否则,窗体是打开的,则返回窗体的值 If IsNull(gctlInputCommonuseCalled.Value) Or gctlInputCommonuseCalled.ControlType <> acTextBox Then '如果控件的值为空,这不是文本框,则直接赋值为选定的词条 gctlInputCommonuseCalled.Value = Forms(cstrFormName).Controls(cstrCtlName).Value Else '否则,在光标位置插入选定的词条 gctlInputCommonuseCalled.Value = Left$(gctlInputCommonuseCalled.Value, gintCtlCalledSelStart) & _ Forms(cstrFormName).Controls(cstrCtlName).Value & _ Mid$(gctlInputCommonuseCalled.Value, gintCtlCalledSellength + gintCtlCalledSelStart + 1) End If Err.Clear '关闭窗体 DoCmd.Close acForm, cstrFormName End IfEnd Function
相关讨论贴子:http://www.office-cn.net/bbs/dispbbs.asp?BoardID=3&ID=19273
tmtony评:很有新意:)