Inserting date into string

可紊 提交于 2019-12-24 03:44:34

问题


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

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?


回答1:


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

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



来源:https://stackoverflow.com/questions/29924075/inserting-date-into-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!