插入日期为字符串 [英] Inserting date into string

查看:146
本文介绍了插入日期为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VBA,我在等于像这样的字符串形式设置的域:

In VBA, I am setting a field in a form equal to a string like so:

tmpNum=1
me.field="DD" & Format(DATE, "mmddyy") & tmpNum

为了今天,我想me.field是DD0428151而是整个格式(DATE,MMDDYY)语句看似什么都不做,我的形式得到DD1。

For today I would want me.field to be DD0428151 but instead the whole Format(DATE, "mmddyy") statement seemingly does nothing and I get DD1 in the form.

没有人理解为什么日没有出现在我的字符串,以及如何解决它?

Does anyone understand why the date isn't appearing in my string and how to fix it?

推荐答案

这样奇怪的事情都可能发生,如果你有一个名为日期您的表和/或现场控制命名为日期的形式。他们将(至少有时)需要precedence通过内置的日期函数,如果它们包含那么结果可能是类似于你的描述。

Strange things like this can happen if you have a field named Date in your table and/or a control named Date on your form. They will (at least sometimes) take precedence over the built-in Date function, and if they contain Null then the results can be similar to what you describe.

如果可能,从日期修改字段的名称更具说明性(或至少是不同的)。如果你不能改变字段的名称,然后考虑改变窗体的记录源到像

If possible, change the name of the field from Date to something more descriptive (or at least different). If you cannot change the name of the field then consider changing the Record Source of the form to something like

SELECT Table1.Foo, Table1.Date AS TheDate, ... FROM Table1

,然后让你的表单使用 TheDate 时,它需要操作的字段或控件。

and then have your form use TheDate when it needs to manipulate the field or control.

这篇关于插入日期为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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