模块问题 [英] Module problem

查看:55
本文介绍了模块问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为GetDocIndex的模块,它在一个名为CommDocNbrtxt的

控件中计算一个序列号。在表单的BeforeUpdate属性我

有以下代码

Private Sub Form_BeforeUpdate(取消为整数)

I have a module called GetDocIndex which calculates a sequential number in a
control called CommDocNbrtxt. On the BeforeUpdate property of the form I
have the following code
Private Sub Form_BeforeUpdate(Cancel As Integer)


如果Len (Nz(Me.CommDocNbrtxt,"))= 0然后
Me.CommDocNbrtxt.Value = GetDocIndex
结束如果

If Len(Nz(Me.CommDocNbrtxt, "")) = 0 Then
Me.CommDocNbrtxt.Value = GetDocIndex
End If



控件不是''当我打开表单时更新并且当我保存表单时我会收到一条消息,指向此代码表示编译错误预期

变量或函数不是模块。如果我把模块代码放在表格模块中

它也不起作用。

有人可以帮忙吗?

TIA


The control isn''t updated when I open the form and when I save the form I
get a message that points to this code that says Compile error Expected
variable or function not module. If I put the module code in the form module
it doesn''t work either.
Can anyone help here?
TIA

推荐答案

你不能称之为模块,你必须调用模块中的程序。确保没有任何程序与任何模块或任何内置程序具有相同的名称。


-

Wayne Morgan

" Tony Williams" < tw@tcp.com>在消息新闻中写道:bl ********* @ titan.btinternet.com ...
You can''t call a "module", you have to call procedures in the module. Make sure that none
of the procedures have the same name as any module or any built in procedure.

--
Wayne Morgan
"Tony Williams" <tw@tcp.com> wrote in message news:bl*********@titan.btinternet.com...
我有一个名为GetDocIndex的模块,用于计算
控件中的序号叫做CommDocNbrtxt。在表单的BeforeUpdate属性中我有以下代码
Private Sub Form_BeforeUpdate(取消为整数)
I have a module called GetDocIndex which calculates a sequential number in a
control called CommDocNbrtxt. On the BeforeUpdate property of the form I
have the following code
Private Sub Form_BeforeUpdate(Cancel As Integer)

如果Len(Nz(Me.CommDocNbrtxt,& ;"))= 0然后
Me.CommDocNbrtxt.Value = GetDocIndex
结束如果

If Len(Nz(Me.CommDocNbrtxt, "")) = 0 Then
Me.CommDocNbrtxt.Value = GetDocIndex
End If


当我打开表单并保存时,控件不会更新表单我
收到一条消息,指向此代码,表示编译错误预期
变量或函数不是模块。如果我把模块代码放在表格模块中
它也不起作用。
任何人都可以帮忙吗?
TIA


The control isn''t updated when I open the form and when I save the form I
get a message that points to this code that says Compile error Expected
variable or function not module. If I put the module code in the form module
it doesn''t work either.
Can anyone help here?
TIA



谢谢Wayne,但作为一个新手,我有点困惑。这是代码

我的函数

函数GetDocIndex()As String


Dim rsDocs作为DAO.Recordset

Dim intDocIdx As Integer

Dim strLastIdx As String,strNewIdx As String,strSQL As String


''获取最后一个索引今年

strSQL =" SELECT Max([CommDocNbrtxt])As [LastDocIdx]" &安培; _

" FROM [tblDocuments]" &安培; _

" WHERE(右([CommDocNbrtxt],2)=''"& _

右(CStr(年(日期)),2)& ;"'');"

设置rsDocs = CurrentDb.OpenRecordset(strSQL)

使用rsDocs

如果不是.RecordCount = 0然后strLastIdx =

..Fields(LastDocIdx)。价值

。关闭

结束

设置rsDocs = Nothing


''将最后一个索引转换为整数或保留为零

如果不是strLastIdx =""然后intDocIdx = CInt(strLastIdx)


''增加索引

intDocIdx = intDocIdx + 1


' '将2位数年份附加为十进制值

strNewIdx = intDocIdx& "。" &安培;对(CStr(年(日期)),2)


''返回新索引

GetDocIndex = strNewIdx


结束功能


正如我之前所说的,如果我将此代码作为函数放在表单中,我仍然不会使用
得到我的控制权使用正确的数字更新。我在做什么

错了?

谢谢

Tony

" Wayne Morgan" <共*************************** @ hotmail.com>在消息中写道

新闻:Iy ***************** @ newssvr33.news.prodigy.co m ...
Thanks Wayne but being a newbie I''m a little confused. Here is the code for
my "function"
Function GetDocIndex() As String

Dim rsDocs As DAO.Recordset
Dim intDocIdx As Integer
Dim strLastIdx As String, strNewIdx As String, strSQL As String

'' Get the last index for this year
strSQL = "SELECT Max([CommDocNbrtxt]) As [LastDocIdx] " & _
"FROM [tblDocuments] " & _
"WHERE (Right([CommDocNbrtxt], 2) = ''" & _
Right(CStr(Year(Date)), 2) & "'');"
Set rsDocs = CurrentDb.OpenRecordset(strSQL)
With rsDocs
If Not .RecordCount = 0 Then strLastIdx =
..Fields("LastDocIdx").Value
.Close
End With
Set rsDocs = Nothing

'' Convert last index to integer or leave as zero
If Not strLastIdx = "" Then intDocIdx = CInt(strLastIdx)

'' Increment the index
intDocIdx = intDocIdx + 1

'' Append the 2 digit year as decimal value
strNewIdx = intDocIdx & "." & Right(CStr(Year(Date)), 2)

'' Return the new index
GetDocIndex = strNewIdx

End Function

As I said earlier if I put this code as a function in the form I still don''t
get my control to update with the right numbers numbers. What am I doing
wrong here?
Thanks
Tony
"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:Iy*****************@newssvr33.news.prodigy.co m...
你不能称之为模块,你必须调用模块中的程序。使
确保没有任何程序与任何模块或任何内置的
程序具有相同的名称。
-
Wayne Morgan

"托尼威廉斯 < tw@tcp.com>在消息中写道
You can''t call a "module", you have to call procedures in the module. Make sure that none of the procedures have the same name as any module or any built in procedure.
--
Wayne Morgan
"Tony Williams" <tw@tcp.com> wrote in message



news:bl ********* @ titan.btinternet.com ...


news:bl*********@titan.btinternet.com...

我有一个名为GetDocIndex的模块,它在一个名为CommDocNbrtxt的控件中计算序列号
。在表单的BeforeUpdate属性中我有以下代码
Private Sub Form_BeforeUpdate(取消为整数)
I have a module called GetDocIndex which calculates a sequential number in a control called CommDocNbrtxt. On the BeforeUpdate property of the form I
have the following code
Private Sub Form_BeforeUpdate(Cancel As Integer)

如果Len(Nz(Me.CommDocNbrtxt,& ;"))= 0然后
Me.CommDocNbrtxt.Value = GetDocIndex
结束如果

If Len(Nz(Me.CommDocNbrtxt, "")) = 0 Then
Me.CommDocNbrtxt.Value = GetDocIndex
End If


当我打开表单并保存时,控件不会更新form
我收到一条消息,指向此代码,表示编译错误预期
变量或函数不是模块。如果我把模块代码放在
模块的形式中它也不起作用。
任何人都可以在这里帮忙吗?
TIA


The control isn''t updated when I open the form and when I save the form I get a message that points to this code that says Compile error Expected
variable or function not module. If I put the module code in the form module it doesn''t work either.
Can anyone help here?
TIA




你把这段代码放在哪里?如果您只是添加该功能,则需要

告诉Access运行该功能。在什么情况下你想要这个

函数运行?这将决定您对此功能的调用位置。对于

示例,如果您希望每次移动到另一条记录时都运行该函数,您将在Form'的OnCurrent事件中调用它。
。您还可以将其用作未绑定文本框的控件

来源。为此,将文本框的控制源设置为


= GetDocIndex


-

Wayne摩根

" Tony Williams" < tw@tcp.com>在消息新闻中写道:bl ********** @ titan.btinternet.com ...
Where are you putting this code in the form? If you are just adding the function, you need
something to tell Access to run the function. Under what circumstances do you want this
function to run? That will determine where you place the call to this function. For
example, if you want the function to run each time you move to another record, you would
place a call to it in the Form''s OnCurrent event. You could also use it as the Control
Source for an unbound text box. To do that, set the Control Source of the text box to

=GetDocIndex

--
Wayne Morgan
"Tony Williams" <tw@tcp.com> wrote in message news:bl**********@titan.btinternet.com...
谢谢Wayne但是作为一个新手我有点困惑。这是
我的函数的代码
函数GetDocIndex()As String

Dim rsDocs作为DAO.Recordset
Dim intDocIdx作为整数
Dim strLastIdx As String,strNewIdx As String,strSQL As String

''获取今年的最后一个索引
strSQL =" SELECT Max([CommDocNbrtxt])As [LastDocIdx]" &安培; _
" FROM [tblDocuments]" &安培; _
  WHERE(右([CommDocNbrtxt],2)=''"& _
对(CStr(年(日期)),2)&"'');" ;
设置rsDocs = CurrentDb.OpenRecordset(strSQL)
使用rsDocs
如果不是.RecordCount = 0那么strLastIdx =
.Fields(" LastDocIdx")。Value
。关闭
结束
设置rsDocs = Nothing

''将最后一个索引转换为整数或保留为零
如果不是strLastIdx =""然后intDocIdx = CInt(strLastIdx)

''增加索引
intDocIdx = intDocIdx + 1

''将2位数年份附加为十进制值
strNewIdx = intDocIdx& "。" &安培;对(CStr(年(日)),2)

''返回新索引
GetDocIndex = strNewIdx

结束功能

>正如我之前所说的,如果我将此代码作为函数放在表单中,我仍然不会让我的控件更新正确的数字。我在做什么
错了?
谢谢
Tony
Thanks Wayne but being a newbie I''m a little confused. Here is the code for
my "function"
Function GetDocIndex() As String

Dim rsDocs As DAO.Recordset
Dim intDocIdx As Integer
Dim strLastIdx As String, strNewIdx As String, strSQL As String

'' Get the last index for this year
strSQL = "SELECT Max([CommDocNbrtxt]) As [LastDocIdx] " & _
"FROM [tblDocuments] " & _
"WHERE (Right([CommDocNbrtxt], 2) = ''" & _
Right(CStr(Year(Date)), 2) & "'');"
Set rsDocs = CurrentDb.OpenRecordset(strSQL)
With rsDocs
If Not .RecordCount = 0 Then strLastIdx =
.Fields("LastDocIdx").Value
.Close
End With
Set rsDocs = Nothing

'' Convert last index to integer or leave as zero
If Not strLastIdx = "" Then intDocIdx = CInt(strLastIdx)

'' Increment the index
intDocIdx = intDocIdx + 1

'' Append the 2 digit year as decimal value
strNewIdx = intDocIdx & "." & Right(CStr(Year(Date)), 2)

'' Return the new index
GetDocIndex = strNewIdx

End Function

As I said earlier if I put this code as a function in the form I still don''t
get my control to update with the right numbers numbers. What am I doing
wrong here?
Thanks
Tony



这篇关于模块问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆