使用日期作为主键 - 并为2007年的每个日期分配记录 [英] Use a date as a primary key - and assign a record to each date in 2007

查看:140
本文介绍了使用日期作为主键 - 并为2007年的每个日期分配记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在创建一个表格,我想用日期作为主键 -

并自动为每个创建一个记录工作日期(例如周一至

周五)至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,

推荐答案

使用日期作为主键的坏主意。访问处理日期不规律。我将于2006年5月4日解释为04/05/2006。访问可能会将其解释为4月5日

2006

您可以拥有一个名为Todat并将其默认值设置为Date(),其中

表示您输入的任何内容将自动拥有今天的日期。你可以将

设置为索引 - 是(无重复),这只允许你使用该日期一次。这真的是你想要的吗?


Phil

" keri" < ke ********* @ diageo.comwrote in message

news:11 ********************* *@j27g2000cwj.googlegr oups.com ...
Bad idea using date as primary key. Access handles dates erratically. I
interpret 04/05/2006 as 4th May 2006. Access may interpret it as 5th April
2006
You can have a field called Todat and set it''s default value as Date() which
means that anythin you enter will automatically have todays date. You can
also set is as indexed - Yes (No Duplicates), which will only allow you to
use that date once. Is that really what you want?

Phil
"keri" <ke*********@diageo.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...




我正在创建一个我想要的表格使用日期作为主键 -

并自动创建每个工作日期的记录(例如周一至

周五),直到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,



可能 - 但我不这么认为。


我的数据库用于规划。我希望我的用户在一年中的每个工作日分配一个类别(名为P1

到P6)。 (这将在Outlook中填写

预约,以便在日历上显示)。但是,如果我直接向outlook执行此操作

(例如,用户通过表单输入此内容并且我将代码

来创建Outlook中的约会),用户将不得不轻弹

在outlook日历和数据库之间查看哪些日期没有

分配了一个类别。


但是如果我能有一张桌子已经包含每天

的记录,然后他们可以查看这个以查看他们仍需要哪些日期

来分配类别。


这有意义吗?我可能会以错误的方式解决这个问题。

Possibly - but I don''t think so.

My db is for planning. I want my users to assign a category (named P1
to P6) to each working day in a year. (This will populate an
appointment in outlook to show on the calendar). However if I do this
directly to outlook (eg the user enters this through a form and I code
it to create the appointment in outlook) the user would have to flick
between the outlook calendar and the db to see which days have not been
assigned a category.

However if I could have a table which already contained a record for
each day then they could view this to see which dates they still needed
to assign categories to.

Does this make sense? I may be going about this in the wrong way.


" keri" < ke ********* @ diageo.comwrote in news:1169571384.868871.109610

@ j27g2000cwj.googlegroups.com:
"keri" <ke*********@diageo.comwrote in news:1169571384.868871.109610
@j27g2000cwj.googlegroups.com:




我正在创建一个表格,我想用日期作为主键 -

并自动为每个创建一个记录工作日期(例如周一至

周五)至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.



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年的每个日期分配记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆