简体   繁体   English

访问 VBA 文本框可见如果

[英]Access VBA Text Box Visible If

I have a simple access database that holds contacts.我有一个包含联系人的简单访问数据库。 My people table has a column named "Last Contact" that is a date value representing the date of last contact.我的 people 表有一个名为“Last Contact”的列,它是一个表示最后一次联系日期的日期值。 On my main screen I have a form that displays the person's information, including the "Last Contact" date.在我的主屏幕上,我有一个显示此人信息的表单,包括“上次联系”日期。

I need to build in an alert system that let's users know when it has been longer than 30 days since the last contact date.我需要建立一个警报系统,让用户知道自上次联系日期起已超过 30 天。 I have built a simple text box that accomplishes this by displaying the text "30 Days" in big red letters.我已经构建了一个简单的文本框,它通过以大红色字母显示文本“30 天”来实现这一点。 The name of this text box is "notice."此文本框的名称是“通知”。

My problem comes with having this text box only appear when it has been 30 days or more since the "Last Contact" date.我的问题是只有在距离“上次联系”日期 30 天或更长时间后才会出现此文本框。 I am using the code below:我正在使用下面的代码:

Sub notice()
Dim dateone As Date
Dim datetwo As Date
Dim days As Integer
Dim notice As Object

dateone = Last_Contact!
datetwo = Date
days = DateDiff("d", dateone, datetwo)
notice = [notice]

If days >= 30 Then
notice.Visible = True
Else
notice.Visible = False
End If
End Sub

When I run this, I get an "Overflow" error.当我运行它时,出现“溢出”错误。 Can someone please assist me with this?有人可以帮助我吗?

Thank you in advance.先感谢您。

Note that if you make the textbox via UI like if you drag a textbox to the form, you do not need to declare it.请注意,如果您通过 UI 制作文本框,就像将文本框拖到表单中一样,则不需要声明它。 And also can you be more specific or provide a screenshot of where you getting the overflow?并且您能否更具体或提供您在哪里获得溢出的屏幕截图?

Hmmm, you seem to have a field, a sub, and a variable all named 'notice' - not a good idea.嗯,您似乎有一个字段、一个子项和一个变量,所有名称都命名为“通知”——这不是一个好主意。

And presumably the line "dateone = Last_Contact!"大概是“dateone = Last_Contact!” is a typo?是错别字吗?

Try using the source of field [notice] as:尝试使用字段 [notice] 的来源作为:

=iif(DateDiff("d", dateone, Date())>=30,"30 Days",Null)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM