PC Review


Reply
Thread Tools Rate Thread

Calculate age as of date in other table

 
 
=?Utf-8?B?ZGVl?=
Guest
Posts: n/a
 
      4th Nov 2007
I have a DOB field in table1 and an Age field in table1 as well.

In table2, I have a field that contains a date that respondents answered
specific questionnaires.

For historical purposes, I would like to capture the age of the person at
the time one questionnaire in particular was answered in the Age field of
table1.

I'm not sure how to go about this, especially since I need the questionnaire
date to be for a specific questionnaire, i.e. questionnaireID 05 specifically.

I have searched high and low and can't seem to find anything like this. Any
help would be greatly appreciated!
--
Thanks!

Dee
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      4th Nov 2007
You haven't really given us much to go on, but to calculate age at a
particular date in time, you'd use

DateDiff("yyyy", [DOB], [SpecificDate]) - _
IIf(Format([SpecificeDate], "mmdd") < Format([DOB], "mmdd"), 1, 0)

In general, you shouldn't store ages. I suppose that since this particular
age will never change, it might be okay to store it instead of the DOB.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"dee" <(E-Mail Removed)> wrote in message
news:9720D132-2C29-4E01-92A4-(E-Mail Removed)...
>I have a DOB field in table1 and an Age field in table1 as well.
>
> In table2, I have a field that contains a date that respondents answered
> specific questionnaires.
>
> For historical purposes, I would like to capture the age of the person at
> the time one questionnaire in particular was answered in the Age field of
> table1.
>
> I'm not sure how to go about this, especially since I need the
> questionnaire
> date to be for a specific questionnaire, i.e. questionnaireID 05
> specifically.
>
> I have searched high and low and can't seem to find anything like this.
> Any
> help would be greatly appreciated!
> --
> Thanks!
>
> Dee



 
Reply With Quote
 
=?Utf-8?B?ZGVl?=
Guest
Posts: n/a
 
      4th Nov 2007
Thanks for your response. I'm sorry, I thought I had provided enough
information.

I guess where I am having difficulty is referencing the Interview Date field
in another table. I'll try to be more clear:

tblParticipants
pptID (autonumber PK)
First
Last
DOB
etc.

tblResponses
responseID (autonumber PK)
pptID (fk)
questionnaireID (fk) (there are several questionnaires)
interviewDate
interviewLanguage
interviewerID (fk)
etc.

I need to determine the Age of the participant as of the (tblResponses)
interviewDate of questionnaireID **5** only, putting the result in the
tblParticipants.

I realize that this is unusual, but for historical purposes only, plus the
fact that the data will be exported to a statistical package that requires
this field, it's really the only choice I have.

Thanks so much for your help - I hope I have provided enough detail.



--
Thanks!

Dee


"Douglas J. Steele" wrote:

> You haven't really given us much to go on, but to calculate age at a
> particular date in time, you'd use
>
> DateDiff("yyyy", [DOB], [SpecificDate]) - _
> IIf(Format([SpecificeDate], "mmdd") < Format([DOB], "mmdd"), 1, 0)
>
> In general, you shouldn't store ages. I suppose that since this particular
> age will never change, it might be okay to store it instead of the DOB.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "dee" <(E-Mail Removed)> wrote in message
> news:9720D132-2C29-4E01-92A4-(E-Mail Removed)...
> >I have a DOB field in table1 and an Age field in table1 as well.
> >
> > In table2, I have a field that contains a date that respondents answered
> > specific questionnaires.
> >
> > For historical purposes, I would like to capture the age of the person at
> > the time one questionnaire in particular was answered in the Age field of
> > table1.
> >
> > I'm not sure how to go about this, especially since I need the
> > questionnaire
> > date to be for a specific questionnaire, i.e. questionnaireID 05
> > specifically.
> >
> > I have searched high and low and can't seem to find anything like this.
> > Any
> > help would be greatly appreciated!
> > --
> > Thanks!
> >
> > Dee

>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      4th Nov 2007
You could create a query along the lines of:

SELECT responseID, pptID, questionnaireID,
interviewDate,
DateDiff("yyyy", tblParticpants.DOB, tblResponses.interviewDate) -
IIf(Format(tblResponses.interviewDate, "mmdd") < Format(tblParticipants.DOB,
"mmdd"), 1, 0) AS Age,
interviewLanguage, interviewerID, ...
FROM tblResponses INNER JOIN tblParticipants
ON tblResponses.pptID = tblParticipants.pptID
WHERE questionnaireID = 5
UNION
SELECT responseID, pptID, questionnaireID,
interviewDate,
Null,
interviewLanguage, interviewerID, ...
FROM tblResponses
WHERE questionnaireID <> 5

What this would do is give you an additional field Age that would only be
populated for Question 5.

You'd then be able to use that query anywhere you would otherwise have used
tblResponses.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"dee" <(E-Mail Removed)> wrote in message
news:F16EB37B-F74B-4128-BAF8-(E-Mail Removed)...
> Thanks for your response. I'm sorry, I thought I had provided enough
> information.
>
> I guess where I am having difficulty is referencing the Interview Date
> field
> in another table. I'll try to be more clear:
>
> tblParticipants
> pptID (autonumber PK)
> First
> Last
> DOB
> etc.
>
> tblResponses
> responseID (autonumber PK)
> pptID (fk)
> questionnaireID (fk) (there are several questionnaires)
> interviewDate
> interviewLanguage
> interviewerID (fk)
> etc.
>
> I need to determine the Age of the participant as of the (tblResponses)
> interviewDate of questionnaireID **5** only, putting the result in the
> tblParticipants.
>
> I realize that this is unusual, but for historical purposes only, plus the
> fact that the data will be exported to a statistical package that requires
> this field, it's really the only choice I have.
>
> Thanks so much for your help - I hope I have provided enough detail.
>
>
>
> --
> Thanks!
>
> Dee
>
>
> "Douglas J. Steele" wrote:
>
>> You haven't really given us much to go on, but to calculate age at a
>> particular date in time, you'd use
>>
>> DateDiff("yyyy", [DOB], [SpecificDate]) - _
>> IIf(Format([SpecificeDate], "mmdd") < Format([DOB], "mmdd"), 1, 0)
>>
>> In general, you shouldn't store ages. I suppose that since this
>> particular
>> age will never change, it might be okay to store it instead of the DOB.
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no private e-mails, please)
>>
>>
>> "dee" <(E-Mail Removed)> wrote in message
>> news:9720D132-2C29-4E01-92A4-(E-Mail Removed)...
>> >I have a DOB field in table1 and an Age field in table1 as well.
>> >
>> > In table2, I have a field that contains a date that respondents
>> > answered
>> > specific questionnaires.
>> >
>> > For historical purposes, I would like to capture the age of the person
>> > at
>> > the time one questionnaire in particular was answered in the Age field
>> > of
>> > table1.
>> >
>> > I'm not sure how to go about this, especially since I need the
>> > questionnaire
>> > date to be for a specific questionnaire, i.e. questionnaireID 05
>> > specifically.
>> >
>> > I have searched high and low and can't seem to find anything like this.
>> > Any
>> > help would be greatly appreciated!
>> > --
>> > Thanks!
>> >
>> > Dee

>>
>>
>>



 
Reply With Quote
 
yanwanli4622
Guest
Posts: n/a
 
      6th Nov 2007

"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> 写入消息新闻:%(E-Mail Removed)...
> You haven't really given us much to go on, but to calculate age at a
> particular date in time, you'd use
>
> DateDiff("yyyy", [DOB], [SpecificDate]) - _
> IIf(Format([SpecificeDate], "mmdd") < Format([DOB], "mmdd"), 1, 0)
>
> In general, you shouldn't store ages. I suppose that since this particular
> age will never change, it might be okay to store it instead of the DOB.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "dee" <(E-Mail Removed)> wrote in message
> news:9720D132-2C29-4E01-92A4-(E-Mail Removed)...
>>I have a DOB field in table1 and an Age field in table1 as well.
>>
>> In table2, I have a field that contains a date that respondents answered
>> specific questionnaires.
>>
>> For historical purposes, I would like to capture the age of the person at
>> the time one questionnaire in particular was answered in the Age field of
>> table1.
>>
>> I'm not sure how to go about this, especially since I need the
>> questionnaire
>> date to be for a specific questionnaire, i.e. questionnaireID 05
>> specifically.
>>
>> I have searched high and low and can't seem to find anything like this.
>> Any
>> help would be greatly appreciated!
>> --
>> Thanks!
>>
>> Dee

>
>



 
Reply With Quote
 
=?Utf-8?B?ZGVl?=
Guest
Posts: n/a
 
      6th Nov 2007
I posted back yesterday, but just checked and see that for some reason it was
never posted.

I seem to be doing something wrong with the code you sent - I can't seem to
get it to work.

The code I have been using generates what I want when I view it in
datasheet, but I can't seem to apply it to a control on my form - the control
just stays blank. Here is the code:

SELECT tbl_participants.ppt_id,
Int(DateDiff("d",[ppt_dob],[completion_date])/365.25) AS Age
FROM tbl_questionnaires INNER JOIN (tbl_participants INNER JOIN
tbl_responses ON tbl_participants.ppt_id = tbl_responses.ppt_id) ON
tbl_questionnaires.qstnaire_id = tbl_responses.qstnaire_id
WHERE (((tbl_responses.qstnaire_id)=2));

Any help is greatly appreciated! Thanks so much.

--
Thanks!

Dee


"Douglas J. Steele" wrote:

> You could create a query along the lines of:
>
> SELECT responseID, pptID, questionnaireID,
> interviewDate,
> DateDiff("yyyy", tblParticpants.DOB, tblResponses.interviewDate) -
> IIf(Format(tblResponses.interviewDate, "mmdd") < Format(tblParticipants.DOB,
> "mmdd"), 1, 0) AS Age,
> interviewLanguage, interviewerID, ...
> FROM tblResponses INNER JOIN tblParticipants
> ON tblResponses.pptID = tblParticipants.pptID
> WHERE questionnaireID = 5
> UNION
> SELECT responseID, pptID, questionnaireID,
> interviewDate,
> Null,
> interviewLanguage, interviewerID, ...
> FROM tblResponses
> WHERE questionnaireID <> 5
>
> What this would do is give you an additional field Age that would only be
> populated for Question 5.
>
> You'd then be able to use that query anywhere you would otherwise have used
> tblResponses.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "dee" <(E-Mail Removed)> wrote in message
> news:F16EB37B-F74B-4128-BAF8-(E-Mail Removed)...
> > Thanks for your response. I'm sorry, I thought I had provided enough
> > information.
> >
> > I guess where I am having difficulty is referencing the Interview Date
> > field
> > in another table. I'll try to be more clear:
> >
> > tblParticipants
> > pptID (autonumber PK)
> > First
> > Last
> > DOB
> > etc.
> >
> > tblResponses
> > responseID (autonumber PK)
> > pptID (fk)
> > questionnaireID (fk) (there are several questionnaires)
> > interviewDate
> > interviewLanguage
> > interviewerID (fk)
> > etc.
> >
> > I need to determine the Age of the participant as of the (tblResponses)
> > interviewDate of questionnaireID **5** only, putting the result in the
> > tblParticipants.
> >
> > I realize that this is unusual, but for historical purposes only, plus the
> > fact that the data will be exported to a statistical package that requires
> > this field, it's really the only choice I have.
> >
> > Thanks so much for your help - I hope I have provided enough detail.
> >
> >
> >
> > --
> > Thanks!
> >
> > Dee
> >
> >
> > "Douglas J. Steele" wrote:
> >
> >> You haven't really given us much to go on, but to calculate age at a
> >> particular date in time, you'd use
> >>
> >> DateDiff("yyyy", [DOB], [SpecificDate]) - _
> >> IIf(Format([SpecificeDate], "mmdd") < Format([DOB], "mmdd"), 1, 0)
> >>
> >> In general, you shouldn't store ages. I suppose that since this
> >> particular
> >> age will never change, it might be okay to store it instead of the DOB.
> >>
> >> --
> >> Doug Steele, Microsoft Access MVP
> >> http://I.Am/DougSteele
> >> (no private e-mails, please)
> >>
> >>
> >> "dee" <(E-Mail Removed)> wrote in message
> >> news:9720D132-2C29-4E01-92A4-(E-Mail Removed)...
> >> >I have a DOB field in table1 and an Age field in table1 as well.
> >> >
> >> > In table2, I have a field that contains a date that respondents
> >> > answered
> >> > specific questionnaires.
> >> >
> >> > For historical purposes, I would like to capture the age of the person
> >> > at
> >> > the time one questionnaire in particular was answered in the Age field
> >> > of
> >> > table1.
> >> >
> >> > I'm not sure how to go about this, especially since I need the
> >> > questionnaire
> >> > date to be for a specific questionnaire, i.e. questionnaireID 05
> >> > specifically.
> >> >
> >> > I have searched high and low and can't seem to find anything like this.
> >> > Any
> >> > help would be greatly appreciated!
> >> > --
> >> > Thanks!
> >> >
> >> > Dee
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      6th Nov 2007
That approach to calculating age is flawed.

I don't understand what you mean that you "can't seem to apply it to a
control on my form". How are you trying to use it?

For that matter, what's the problem with the code I gave you? "can't seem to
get it to work" doesn't tell me much.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"dee" <(E-Mail Removed)> wrote in message
news:27058765-A66C-4601-BB05-(E-Mail Removed)...
>I posted back yesterday, but just checked and see that for some reason it
>was
> never posted.
>
> I seem to be doing something wrong with the code you sent - I can't seem
> to
> get it to work.
>
> The code I have been using generates what I want when I view it in
> datasheet, but I can't seem to apply it to a control on my form - the
> control
> just stays blank. Here is the code:
>
> SELECT tbl_participants.ppt_id,
> Int(DateDiff("d",[ppt_dob],[completion_date])/365.25) AS Age
> FROM tbl_questionnaires INNER JOIN (tbl_participants INNER JOIN
> tbl_responses ON tbl_participants.ppt_id = tbl_responses.ppt_id) ON
> tbl_questionnaires.qstnaire_id = tbl_responses.qstnaire_id
> WHERE (((tbl_responses.qstnaire_id)=2));
>
> Any help is greatly appreciated! Thanks so much.
>
> --
> Thanks!
>
> Dee
>
>
> "Douglas J. Steele" wrote:
>
>> You could create a query along the lines of:
>>
>> SELECT responseID, pptID, questionnaireID,
>> interviewDate,
>> DateDiff("yyyy", tblParticpants.DOB, tblResponses.interviewDate) -
>> IIf(Format(tblResponses.interviewDate, "mmdd") <
>> Format(tblParticipants.DOB,
>> "mmdd"), 1, 0) AS Age,
>> interviewLanguage, interviewerID, ...
>> FROM tblResponses INNER JOIN tblParticipants
>> ON tblResponses.pptID = tblParticipants.pptID
>> WHERE questionnaireID = 5
>> UNION
>> SELECT responseID, pptID, questionnaireID,
>> interviewDate,
>> Null,
>> interviewLanguage, interviewerID, ...
>> FROM tblResponses
>> WHERE questionnaireID <> 5
>>
>> What this would do is give you an additional field Age that would only be
>> populated for Question 5.
>>
>> You'd then be able to use that query anywhere you would otherwise have
>> used
>> tblResponses.
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no private e-mails, please)
>>
>>
>> "dee" <(E-Mail Removed)> wrote in message
>> news:F16EB37B-F74B-4128-BAF8-(E-Mail Removed)...
>> > Thanks for your response. I'm sorry, I thought I had provided enough
>> > information.
>> >
>> > I guess where I am having difficulty is referencing the Interview Date
>> > field
>> > in another table. I'll try to be more clear:
>> >
>> > tblParticipants
>> > pptID (autonumber PK)
>> > First
>> > Last
>> > DOB
>> > etc.
>> >
>> > tblResponses
>> > responseID (autonumber PK)
>> > pptID (fk)
>> > questionnaireID (fk) (there are several questionnaires)
>> > interviewDate
>> > interviewLanguage
>> > interviewerID (fk)
>> > etc.
>> >
>> > I need to determine the Age of the participant as of the (tblResponses)
>> > interviewDate of questionnaireID **5** only, putting the result in the
>> > tblParticipants.
>> >
>> > I realize that this is unusual, but for historical purposes only, plus
>> > the
>> > fact that the data will be exported to a statistical package that
>> > requires
>> > this field, it's really the only choice I have.
>> >
>> > Thanks so much for your help - I hope I have provided enough detail.
>> >
>> >
>> >
>> > --
>> > Thanks!
>> >
>> > Dee
>> >
>> >
>> > "Douglas J. Steele" wrote:
>> >
>> >> You haven't really given us much to go on, but to calculate age at a
>> >> particular date in time, you'd use
>> >>
>> >> DateDiff("yyyy", [DOB], [SpecificDate]) - _
>> >> IIf(Format([SpecificeDate], "mmdd") < Format([DOB], "mmdd"), 1, 0)
>> >>
>> >> In general, you shouldn't store ages. I suppose that since this
>> >> particular
>> >> age will never change, it might be okay to store it instead of the
>> >> DOB.
>> >>
>> >> --
>> >> Doug Steele, Microsoft Access MVP
>> >> http://I.Am/DougSteele
>> >> (no private e-mails, please)
>> >>
>> >>
>> >> "dee" <(E-Mail Removed)> wrote in message
>> >> news:9720D132-2C29-4E01-92A4-(E-Mail Removed)...
>> >> >I have a DOB field in table1 and an Age field in table1 as well.
>> >> >
>> >> > In table2, I have a field that contains a date that respondents
>> >> > answered
>> >> > specific questionnaires.
>> >> >
>> >> > For historical purposes, I would like to capture the age of the
>> >> > person
>> >> > at
>> >> > the time one questionnaire in particular was answered in the Age
>> >> > field
>> >> > of
>> >> > table1.
>> >> >
>> >> > I'm not sure how to go about this, especially since I need the
>> >> > questionnaire
>> >> > date to be for a specific questionnaire, i.e. questionnaireID 05
>> >> > specifically.
>> >> >
>> >> > I have searched high and low and can't seem to find anything like
>> >> > this.
>> >> > Any
>> >> > help would be greatly appreciated!
>> >> > --
>> >> > Thanks!
>> >> >
>> >> > Dee
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?ZGVl?=
Guest
Posts: n/a
 
      6th Nov 2007
Sorry, I should have explained that. The Age field doesn't contain any values.

Here is the code as per your instructions, with one minor modification. I
kept getting error 3079, so in the SELECT part, identified pp_id as coming
from tbl_responses. Maybe that's the problem?

SELECT response_id, tbl_responses.ppt_id, qstnaire_id, completion_date,
DateDiff("yyyy",[tbl_participants].[ppt_dob],[tbl_responses].[competion_date])-IIf(Format([tbl_responses].[completion_date],"mmdd")<Format([tbl_participants].[ppt_dob],"mmdd"),1,0)
AS Age, interviewer_id, start_time, end_time, interview_lang
FROM tbl_responses INNER JOIN tbl_participants ON tbl_responses.ppt_id =
tbl_participants.ppt_id
WHERE qstnaire_id=2 UNION SELECT response_id, ppt_id, qstnaire_id,
completion_date, Null,interviewer_id, start_time, end_time, interview_lang
FROM tbl_responses WHERE qstnaire_id <> 2;
--
Thanks!

Dee


"Douglas J. Steele" wrote:

> That approach to calculating age is flawed.
>
> I don't understand what you mean that you "can't seem to apply it to a
> control on my form". How are you trying to use it?
>
> For that matter, what's the problem with the code I gave you? "can't seem to
> get it to work" doesn't tell me much.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "dee" <(E-Mail Removed)> wrote in message
> news:27058765-A66C-4601-BB05-(E-Mail Removed)...
> >I posted back yesterday, but just checked and see that for some reason it
> >was
> > never posted.
> >
> > I seem to be doing something wrong with the code you sent - I can't seem
> > to
> > get it to work.
> >
> > The code I have been using generates what I want when I view it in
> > datasheet, but I can't seem to apply it to a control on my form - the
> > control
> > just stays blank. Here is the code:
> >
> > SELECT tbl_participants.ppt_id,
> > Int(DateDiff("d",[ppt_dob],[completion_date])/365.25) AS Age
> > FROM tbl_questionnaires INNER JOIN (tbl_participants INNER JOIN
> > tbl_responses ON tbl_participants.ppt_id = tbl_responses.ppt_id) ON
> > tbl_questionnaires.qstnaire_id = tbl_responses.qstnaire_id
> > WHERE (((tbl_responses.qstnaire_id)=2));
> >
> > Any help is greatly appreciated! Thanks so much.
> >
> > --
> > Thanks!
> >
> > Dee
> >
> >
> > "Douglas J. Steele" wrote:
> >
> >> You could create a query along the lines of:
> >>
> >> SELECT responseID, pptID, questionnaireID,
> >> interviewDate,
> >> DateDiff("yyyy", tblParticpants.DOB, tblResponses.interviewDate) -
> >> IIf(Format(tblResponses.interviewDate, "mmdd") <
> >> Format(tblParticipants.DOB,
> >> "mmdd"), 1, 0) AS Age,
> >> interviewLanguage, interviewerID, ...
> >> FROM tblResponses INNER JOIN tblParticipants
> >> ON tblResponses.pptID = tblParticipants.pptID
> >> WHERE questionnaireID = 5
> >> UNION
> >> SELECT responseID, pptID, questionnaireID,
> >> interviewDate,
> >> Null,
> >> interviewLanguage, interviewerID, ...
> >> FROM tblResponses
> >> WHERE questionnaireID <> 5
> >>
> >> What this would do is give you an additional field Age that would only be
> >> populated for Question 5.
> >>
> >> You'd then be able to use that query anywhere you would otherwise have
> >> used
> >> tblResponses.
> >>
> >> --
> >> Doug Steele, Microsoft Access MVP
> >> http://I.Am/DougSteele
> >> (no private e-mails, please)
> >>
> >>
> >> "dee" <(E-Mail Removed)> wrote in message
> >> news:F16EB37B-F74B-4128-BAF8-(E-Mail Removed)...
> >> > Thanks for your response. I'm sorry, I thought I had provided enough
> >> > information.
> >> >
> >> > I guess where I am having difficulty is referencing the Interview Date
> >> > field
> >> > in another table. I'll try to be more clear:
> >> >
> >> > tblParticipants
> >> > pptID (autonumber PK)
> >> > First
> >> > Last
> >> > DOB
> >> > etc.
> >> >
> >> > tblResponses
> >> > responseID (autonumber PK)
> >> > pptID (fk)
> >> > questionnaireID (fk) (there are several questionnaires)
> >> > interviewDate
> >> > interviewLanguage
> >> > interviewerID (fk)
> >> > etc.
> >> >
> >> > I need to determine the Age of the participant as of the (tblResponses)
> >> > interviewDate of questionnaireID **5** only, putting the result in the
> >> > tblParticipants.
> >> >
> >> > I realize that this is unusual, but for historical purposes only, plus
> >> > the
> >> > fact that the data will be exported to a statistical package that
> >> > requires
> >> > this field, it's really the only choice I have.
> >> >
> >> > Thanks so much for your help - I hope I have provided enough detail.
> >> >
> >> >
> >> >
> >> > --
> >> > Thanks!
> >> >
> >> > Dee
> >> >
> >> >
> >> > "Douglas J. Steele" wrote:
> >> >
> >> >> You haven't really given us much to go on, but to calculate age at a
> >> >> particular date in time, you'd use
> >> >>
> >> >> DateDiff("yyyy", [DOB], [SpecificDate]) - _
> >> >> IIf(Format([SpecificeDate], "mmdd") < Format([DOB], "mmdd"), 1, 0)
> >> >>
> >> >> In general, you shouldn't store ages. I suppose that since this
> >> >> particular
> >> >> age will never change, it might be okay to store it instead of the
> >> >> DOB.
> >> >>
> >> >> --
> >> >> Doug Steele, Microsoft Access MVP
> >> >> http://I.Am/DougSteele
> >> >> (no private e-mails, please)
> >> >>
> >> >>
> >> >> "dee" <(E-Mail Removed)> wrote in message
> >> >> news:9720D132-2C29-4E01-92A4-(E-Mail Removed)...
> >> >> >I have a DOB field in table1 and an Age field in table1 as well.
> >> >> >
> >> >> > In table2, I have a field that contains a date that respondents
> >> >> > answered
> >> >> > specific questionnaires.
> >> >> >
> >> >> > For historical purposes, I would like to capture the age of the
> >> >> > person
> >> >> > at
> >> >> > the time one questionnaire in particular was answered in the Age
> >> >> > field
> >> >> > of
> >> >> > table1.
> >> >> >
> >> >> > I'm not sure how to go about this, especially since I need the
> >> >> > questionnaire
> >> >> > date to be for a specific questionnaire, i.e. questionnaireID 05
> >> >> > specifically.
> >> >> >
> >> >> > I have searched high and low and can't seem to find anything like
> >> >> > this.
> >> >> > Any
> >> >> > help would be greatly appreciated!
> >> >> > --
> >> >> > Thanks!
> >> >> >
> >> >> > Dee
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
=?Utf-8?B?ZGVl?=
Guest
Posts: n/a
 
      6th Nov 2007
Just realized how incredibly stupid I look. Obviously it worked - I had made
a typo.

I'm really sorry - thanks very much for your patience. Now I need to add
this to a control on my form so that the age is displayed when all other info
is being input, linking it via the ppt_id on the form.
--
Thanks!

Dee


"Douglas J. Steele" wrote:

> That approach to calculating age is flawed.
>
> I don't understand what you mean that you "can't seem to apply it to a
> control on my form". How are you trying to use it?
>
> For that matter, what's the problem with the code I gave you? "can't seem to
> get it to work" doesn't tell me much.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "dee" <(E-Mail Removed)> wrote in message
> news:27058765-A66C-4601-BB05-(E-Mail Removed)...
> >I posted back yesterday, but just checked and see that for some reason it
> >was
> > never posted.
> >
> > I seem to be doing something wrong with the code you sent - I can't seem
> > to
> > get it to work.
> >
> > The code I have been using generates what I want when I view it in
> > datasheet, but I can't seem to apply it to a control on my form - the
> > control
> > just stays blank. Here is the code:
> >
> > SELECT tbl_participants.ppt_id,
> > Int(DateDiff("d",[ppt_dob],[completion_date])/365.25) AS Age
> > FROM tbl_questionnaires INNER JOIN (tbl_participants INNER JOIN
> > tbl_responses ON tbl_participants.ppt_id = tbl_responses.ppt_id) ON
> > tbl_questionnaires.qstnaire_id = tbl_responses.qstnaire_id
> > WHERE (((tbl_responses.qstnaire_id)=2));
> >
> > Any help is greatly appreciated! Thanks so much.
> >
> > --
> > Thanks!
> >
> > Dee
> >
> >
> > "Douglas J. Steele" wrote:
> >
> >> You could create a query along the lines of:
> >>
> >> SELECT responseID, pptID, questionnaireID,
> >> interviewDate,
> >> DateDiff("yyyy", tblParticpants.DOB, tblResponses.interviewDate) -
> >> IIf(Format(tblResponses.interviewDate, "mmdd") <
> >> Format(tblParticipants.DOB,
> >> "mmdd"), 1, 0) AS Age,
> >> interviewLanguage, interviewerID, ...
> >> FROM tblResponses INNER JOIN tblParticipants
> >> ON tblResponses.pptID = tblParticipants.pptID
> >> WHERE questionnaireID = 5
> >> UNION
> >> SELECT responseID, pptID, questionnaireID,
> >> interviewDate,
> >> Null,
> >> interviewLanguage, interviewerID, ...
> >> FROM tblResponses
> >> WHERE questionnaireID <> 5
> >>
> >> What this would do is give you an additional field Age that would only be
> >> populated for Question 5.
> >>
> >> You'd then be able to use that query anywhere you would otherwise have
> >> used
> >> tblResponses.
> >>
> >> --
> >> Doug Steele, Microsoft Access MVP
> >> http://I.Am/DougSteele
> >> (no private e-mails, please)
> >>
> >>
> >> "dee" <(E-Mail Removed)> wrote in message
> >> news:F16EB37B-F74B-4128-BAF8-(E-Mail Removed)...
> >> > Thanks for your response. I'm sorry, I thought I had provided enough
> >> > information.
> >> >
> >> > I guess where I am having difficulty is referencing the Interview Date
> >> > field
> >> > in another table. I'll try to be more clear:
> >> >
> >> > tblParticipants
> >> > pptID (autonumber PK)
> >> > First
> >> > Last
> >> > DOB
> >> > etc.
> >> >
> >> > tblResponses
> >> > responseID (autonumber PK)
> >> > pptID (fk)
> >> > questionnaireID (fk) (there are several questionnaires)
> >> > interviewDate
> >> > interviewLanguage
> >> > interviewerID (fk)
> >> > etc.
> >> >
> >> > I need to determine the Age of the participant as of the (tblResponses)
> >> > interviewDate of questionnaireID **5** only, putting the result in the
> >> > tblParticipants.
> >> >
> >> > I realize that this is unusual, but for historical purposes only, plus
> >> > the
> >> > fact that the data will be exported to a statistical package that
> >> > requires
> >> > this field, it's really the only choice I have.
> >> >
> >> > Thanks so much for your help - I hope I have provided enough detail.
> >> >
> >> >
> >> >
> >> > --
> >> > Thanks!
> >> >
> >> > Dee
> >> >
> >> >
> >> > "Douglas J. Steele" wrote:
> >> >
> >> >> You haven't really given us much to go on, but to calculate age at a
> >> >> particular date in time, you'd use
> >> >>
> >> >> DateDiff("yyyy", [DOB], [SpecificDate]) - _
> >> >> IIf(Format([SpecificeDate], "mmdd") < Format([DOB], "mmdd"), 1, 0)
> >> >>
> >> >> In general, you shouldn't store ages. I suppose that since this
> >> >> particular
> >> >> age will never change, it might be okay to store it instead of the
> >> >> DOB.
> >> >>
> >> >> --
> >> >> Doug Steele, Microsoft Access MVP
> >> >> http://I.Am/DougSteele
> >> >> (no private e-mails, please)
> >> >>
> >> >>
> >> >> "dee" <(E-Mail Removed)> wrote in message
> >> >> news:9720D132-2C29-4E01-92A4-(E-Mail Removed)...
> >> >> >I have a DOB field in table1 and an Age field in table1 as well.
> >> >> >
> >> >> > In table2, I have a field that contains a date that respondents
> >> >> > answered
> >> >> > specific questionnaires.
> >> >> >
> >> >> > For historical purposes, I would like to capture the age of the
> >> >> > person
> >> >> > at
> >> >> > the time one questionnaire in particular was answered in the Age
> >> >> > field
> >> >> > of
> >> >> > table1.
> >> >> >
> >> >> > I'm not sure how to go about this, especially since I need the
> >> >> > questionnaire
> >> >> > date to be for a specific questionnaire, i.e. questionnaireID 05
> >> >> > specifically.
> >> >> >
> >> >> > I have searched high and low and can't seem to find anything like
> >> >> > this.
> >> >> > Any
> >> >> > help would be greatly appreciated!
> >> >> > --
> >> >> > Thanks!
> >> >> >
> >> >> > Dee
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate and store future date in a table =?Utf-8?B?amVubmllYmVudGhhbQ==?= Microsoft Access 14 16th Aug 2007 03:10 PM
Calculate date based on other table EMILYTAN via AccessMonster.com Microsoft Access Form Coding 1 21st May 2007 01:23 PM
Calculate Default Date in a Table =?Utf-8?B?U0RIQERK?= Microsoft Access 1 14th Jun 2006 04:27 PM
Calculate date difference between fixed date and current date Dave Elliott Microsoft Access Forms 3 23rd May 2005 03:54 AM
Re: Excel: auto-calculate a date 2 weeks after an initial date RagDyer Microsoft Excel Worksheet Functions 0 22nd Sep 2004 09:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:06 PM.