MS Access 2003/2007 VBA - 如何从记录集中获取日期字段并以 dd-MMM-yyyy 格式字符串化?

发布于 2024-09-06 18:10:30 字数 575 浏览 0 评论 0原文

我有一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怪异←思 2024-09-13 18:10:30

也许:

oTextRange.Text = Format(rs![Date], "dd-MMM-yyyy")

我将字段名称括在方括号中,因为日期是保留字。但我认为在这种情况下应该没有什么区别。尽管如此,请尽量避免在字段、表和其他对象名称中使用保留字。

Maybe:

oTextRange.Text = Format(rs![Date], "dd-MMM-yyyy")

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.

吝吻 2024-09-13 18:10:30

使用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

冷夜 2024-09-13 18:10:30

好吧,这是我第一次回答自己的问题,所以如果我不应该这样做……抱歉。

我想我会展示我所做的事情,以防其他人想知道

Set oShape = oSlide.Shapes("S1_Date")
Set oTextRange = oShape.TextFrame.TextRange

     oTextRange.Text = Format(rs!Date, "dd-MMM-yyyy")

,仅此而已。对我来说很容易弄清楚自己。

编辑:哎呀...抱歉,当我发布此内容时没有其他答案!

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

Set oShape = oSlide.Shapes("S1_Date")
Set oTextRange = oShape.TextFrame.TextRange

     oTextRange.Text = Format(rs!Date, "dd-MMM-yyyy")

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文