ms access vba unique table 命名方法 datestamp
ms access vba unique table naming method datestamp
我想让创建的 table 名称唯一,可能是在 table 名称中使用 hh:mm:ss 这样如果宏一次又一次地播放,它就不会告诉我 "table name already exists".
查询分为两部分。一种用于创建 table,另一种用于刷新访问数据对象,以便新的 table 可见。
Sub SelectIntoX()
Dim dbs As Database
Set dbs = CurrentDb
' Part 1 Select all records in the scheme table
' and copy them into a new table
dbs.Execute "SELECT * INTO " _
& Format(Date, "yymmdd") & "_Scheme" & " FROM dbo_scheme;"
'Part 2 refresh Access data objects to see new table appear
DBEngine(0)(0).TableDefs.Refresh
DoCmd.SelectObject acTable, Format(Date, "yymmdd") & "_Scheme", True
End Sub
我遇到的问题是 yymmdd 不是唯一的,我每天 运行 很多次。
我也试过这个 hhmmss,但它只会添加零。
这应该是一个不错的选择:
Format(Now(), "yyyymmddhhmmss")
我想让创建的 table 名称唯一,可能是在 table 名称中使用 hh:mm:ss 这样如果宏一次又一次地播放,它就不会告诉我 "table name already exists".
查询分为两部分。一种用于创建 table,另一种用于刷新访问数据对象,以便新的 table 可见。
Sub SelectIntoX()
Dim dbs As Database
Set dbs = CurrentDb
' Part 1 Select all records in the scheme table
' and copy them into a new table
dbs.Execute "SELECT * INTO " _
& Format(Date, "yymmdd") & "_Scheme" & " FROM dbo_scheme;"
'Part 2 refresh Access data objects to see new table appear
DBEngine(0)(0).TableDefs.Refresh
DoCmd.SelectObject acTable, Format(Date, "yymmdd") & "_Scheme", True
End Sub
我遇到的问题是 yymmdd 不是唯一的,我每天 运行 很多次。
我也试过这个 hhmmss,但它只会添加零。
这应该是一个不错的选择:
Format(Now(), "yyyymmddhhmmss")