问题描述
我正在创建一个表格,我想用日期作为主键 -
并自动为每个创建一个记录工作日期(例如周一至
周五)至2007年6月30日。这可能吗?我不希望我的用户
必须为每个日期创建一个记录。
谢谢,
Hi,
I am creating a table where I want to use the date as the primary key -
and to automatically create a record for each working date (eg Mon to
Fri) until 30 June 2007. Is this possible? I do not want my user to
have to create a record for each date.
Thanks,
推荐答案
Dim dateWorking As Date
Dim dateEnd As Date
dateWorking = DateSerial(2006,9,1)
dateEnd = DateSerial(2007,6,30)
With CurrentProject.Connection
.Execute" CREATE TABLE tblDates(fldDate DateTime CONSTRAINT PrimaryKey
主键)
而DateDiff(" d",dateWorking,dateEnd)> = 0
如果是工作日(dateWorking) < 1和工作日(dateWorking)< 7然后_
。执行INSERT INTO tblDates(fldDate)VALUES("& Format
(dateWorking,") ; \ #mm \ / dd \ / yyyy \#\)")
dateWorking = DateAdd(" d",1,dateWorking)
Wend
结束
新闻客户将拆分一些不应拆分的行。这些将需要更正
。
Dim dateWorking As Date
Dim dateEnd As Date
dateWorking = DateSerial(2006, 9, 1)
dateEnd = DateSerial(2007, 6, 30)
With CurrentProject.Connection
.Execute "CREATE TABLE tblDates (fldDate DateTime CONSTRAINT PrimaryKey
Primary Key)"
While DateDiff("d", dateWorking, dateEnd) >= 0
If Weekday(dateWorking) <1 And Weekday(dateWorking) <7 Then _
.Execute "INSERT INTO tblDates (fldDate) VALUES (" & Format
(dateWorking, "\#mm\/dd\/yyyy\#\)")
dateWorking = DateAdd("d", 1, dateWorking)
Wend
End With
News Clients will splits some lines that should not be split. These will
will require correction.
这篇关于使用日期作为主键 - 并为2007年的每个日期分配记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!