Click to See Complete Forum and Search --> : Getting data from MSAccess to greet someone's birthday. Please help.


marksquall
05-30-2006, 12:15 AM
Dear WebDeveloper.com Members,

Hello. Good day to all!

I just want to ask some tips on how could I "extract" data (i.e. date data) from my MSAccess and display someone's name on my page if it is their birthday today.

Initially I have this fields on my MSAccess table named TableEmp:

Name
BMonth
BDay
BYear

Respectively.

When I logged in as an admin on the page, I have the option to add a person on my database, with this following code:

<form name="form" method="post" action="AddNewRecord.asp">
<INPUT type="text" name="wholename">
<SELECT name="BDAY">
<OPTION value=0 selected></OPTION>
<OPTION value=1>1</OPTION>
<OPTION value=2>2</OPTION>
...
<OPTION value=31>31</OPTION>
</SELECT>

<SELECT name="BIRTHMONTH">
<OPTION value=0 selected></OPTION>
<OPTION value=1>January</OPTION>
<OPTION value=2>February</OPTION>
...
<OPTION value=12>December</OPTION>
</SELECT>

<INPUT type="text" maxLength=4 size=4 name="BYEAR">
</form>


In turn, this is the code of my AddNewRecord.asp:

<%
response.Buffer = true
Name=request.form("wholename")
BiMonth=request.form("BIRTHMONTH")
BiDay=request.form("BDAY")
BiYear=request.form("BYEAR")
dim conn, rs
set conn = Server.CreateObject ("ADODB.Connection")
conn.open "Provider = Microsoft.jet.OLEDB.4.0;" & "Data Source = " & _
Server.MapPath ("Database/MyDB.mdb")
set rs = Server.createObject ("ADODB.recordset")
rs.open "INSERT Into TableEmp Name,BMonth,BDay,BYear)
values('" & Name &"','" & BiMonth &"','" & Biday &"','" & "','" & BiYear & "'"
& ")",conn
response.redirect("Main.asp")
%>

So if I logged out, then an "ordinary" employee logged in (with no admin rights) and in case today is his/her birthday, therefore he/she will see his/her name on the left side of the page...greeting in his/her birthday.

I don't know if it is correct to have the date, month, year of the birthday be separated on different data fields on MSAccess, or just in one data field. Because when I click "View Records" when I logged in, I see numbers on birth months and not name of months(I know because I used numbers as values corresponding to months). or should I use another table in MSAccess (let's say tablemonths that has two fields: BMonth and Monthname) that has relationship with BMonth in my TableEmp)

Hope I could be enlighten with this one. I don't know how to make comparisons. I tried some code mentioned here but I didn't work. More power to everyone. Thank you!

Warn regards,
MarkSquall

russell
05-30-2006, 11:28 AM
i'd put the entire date into one field. yours will wok though. use the DatePart function to see if it is the person's birthday

DatePart("m", Date()) '' month
DatePArt("yyyy", Date()) '' year
DatePart("d", Date()) '' day

marksquall
06-12-2006, 09:56 PM
Dear Mr. Russell,


Hello, a pleasant day to you!

In your tip that you had put the entire date data (month, date, year) into ONE field on your database, I just wonder if you could help me how to do it...I mean how to put those three fields in my MSAccess? And if I use number in my select field with regards to months
Example:


<SELECT name="BIRTHMONTH">
<OPTION value=0 selected></OPTION>
<OPTION value=1> January </OPTION>
<OPTION value=2> February </OPTION>
...
<OPTION value=12> December </OPTION>
</SELECT>


Then how can I show that if it's 12, then I should display DECEMBER as an output for viewing (and not 12, because it's the number that shows, not the name of month).

Thank you very much and God bless you and your family.



Warm regards,

Mark Squall

russell
06-12-2006, 11:10 PM
Well, for passing it do the db -- if the date is in one field you'd do something like this

Dim birthdate
Dim mm, dd, yy

mm = Request.Form("birthmonth")
dd = Request.Form("birthday")
yy = Request.Form("birthyear")

birthdate = mm & "/" & dd & "/" & yy
then you'd pass birthdate to the database

To display the month name use the DateName() function

Response.Write DateName("m", mm)

where mm = 12 would display "December"

Hope that helps!

marksquall
06-13-2006, 12:06 AM
Dear Sir Russell,


Well, it's me again, hehehe....

Thank you very much for the code you'd shared with me, I'll try to apply it now ASAP. But last question Sir, in your code:

Response.Write DateName("m", mm)

Does the String "m" a fixed String? I'm new to DateName function, so the function DateName needs that "m" for month? Or is it just a user-defined String? And can DateName function consider four(4) characters for the year? Example: 1982

And I suddenly thought of this another problem:

If the value in the database, for example is 5/23/1981 then I wonder how to "extract" this data when the user (just in case) change the value, isn't that I should display the month, date, year in three (3) separate text fields where the month and date should be in somewhat like a pulldown menu to avoid misspelled months, wrong numbers for dates, etc? I've got this "interactivity" from Yahoo! and other site that has a user-profiles, where when the user click edit or whatever, he could also change his/her birthday.


I hope to hear more from you (again) Sir!


God bless!


Warm regards,

MarkSquall