MS Access 2003/2007 VBA - 如何从记录集中获取日期字段并以 dd-MMM-yyyy 格式字符串化?
我有一些 VB,它使用 DAO 来获取一些数据,其中一个字段是日期字段(如交易日期)。它不是日期/时间,只是简单的日期,如 dd/mm/yyyy。
所以在访问表单上我知道如何做到这一点,但现在我正在研究一些 excel/ppt 自动化。我使用类似这个简单示例 DAO sql 字符串、openrecordset 的东西来获取数据。
假设相关数据只是 rs!Date。
我将它移动到powerpoint,如下所示:
Set oShape = oSlide.Shapes("S1_Date")
Set oTextRange = oShape.textFrame.TextRange
oTextRange.Text = rs!Date
现在我省略了各种内容,但这是将我在记录集中已有的日期传输到ppt pres上的部分,只是以这种格式,
dd/mm/yyyy
我会我真的只是想知道如何简单地将其
"dd-MMM-yyyy"
作为我想要的输出字符串。
谢谢 贾斯汀
i have some VB that uses DAO to grab some data, one field being a date field (as in date of a transaction). its not date/time, just simply date like dd/mm/yyyy.
so on an access form i know how to do this, but right now i am working on some excel/ppt automation. i use something like this simple example DAO sql string, openrecordset to get the data.
So lets say the data in question is just rs!Date.
I move it to powerpoint like so:
Set oShape = oSlide.Shapes("S1_Date")
Set oTextRange = oShape.textFrame.TextRange
oTextRange.Text = rs!Date
now i am leaving out all kinds of stuff, but this is the part that transfers this date that I already have in the recordset, on to the ppt pres just fine, only in this format
dd/mm/yyyy
and i would really just like to know how to simply get this
"dd-MMM-yyyy"
as my desired output string.
thanks
justin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许:
我将字段名称括在方括号中,因为日期是保留字。但我认为在这种情况下应该没有什么区别。尽管如此,请尽量避免在字段、表和其他对象名称中使用保留字。
Maybe:
I enclosed the field name in square brackets because Date is a reserved word. But I don't think it should make any difference in this case. Nevertheless, try to avoid reserved words for your field, table, and other object names.
使用
Format
函数。在调试窗口
Msgbox Format (Now(), "dd-MMM'YYYY")
中尝试此操作。http://office.microsoft.com/en- ca/access-help/format-function-HA001228839.aspx
Use the
Format
function.Try this in the debug window
Msgbox Format (Now(), "dd-MMM'YYYY")
.http://office.microsoft.com/en-ca/access-help/format-function-HA001228839.aspx
好吧,这是我第一次回答自己的问题,所以如果我不应该这样做……抱歉。
我想我会展示我所做的事情,以防其他人想知道
,仅此而已。对我来说很容易弄清楚自己。
编辑:哎呀...抱歉,当我发布此内容时没有其他答案!
Ok so this is the first time I am ever answering my own question, so if i am not supposed to do this....apologies.
i figure i would show what I did incase anyone else wants to know
and that was it. it was easy enough for me to figure out myself.
EDIT: Oops....sorry did not have other answers when i posted this!