Forum Moderators: open
Please help. I'm new to asp and new help with the code I have to create this so users can accurately set up meetings for rooms without worrying about duplicates OR OVERLAPPING SCHEDULES.
Thanks,
Your problem makes perfect sense, and here is the answer:
Someone where on your ASP page is the routine to either Update or Insert the record into the Calendar.
Usually there will be a command that says, If Parameter!= null then...... which starts the update/insert section.
Right after that line you will build a new query using the date requested as the condition of the where clause. If the result set returns EOF, that means the date is open, and you can proceed to insert/update. If the recordset is NOT EOF that means there already is an entry for that date, and you can stop processing here, perhaps send a message back to that effect.
Without seeing your page, it's hard to give you the code for it, but this should help you out.
If you need more help, you can post a snippet of your code and someone will write the syntax. Keep in mind we don't like to see a huge post of code.
Good luck with it!
Here is a snippet of where I think the answer may go, but there may be another area on this addevent page:
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) <> "") Then
MM_editConnection = MM_dsnCoe_STRING
MM_editTable = "tblEvents"
MM_editRedirectUrl = "add_review.asp"
MM_fieldsStr = "published¦value¦listtype¦value¦title¦value¦category¦value¦Location¦value¦description¦value¦start1¦value¦end1¦value¦start2¦value¦end2¦value¦start3¦value¦end3¦value¦start1_t¦value¦end1_t¦value¦start2_t¦value¦end2_t¦value¦start3_t¦value¦end3_t¦value¦contact¦value¦phone2¦value¦office¦value¦email¦value"
MM_columnsStr = "published¦',none,''¦listtype¦',none,''¦title¦',none,''¦category¦',none,''¦Location¦',none,''¦description¦',none,''¦start1¦#,none,NULL¦end1¦#,none,NULL¦start2¦#,none,NULL¦end2¦#,none,NULL¦start3¦#,none,NULL¦end3¦#,none,NULL¦start1_t¦#,none,NULL¦end1_t¦#,none,NULL¦start2_t¦#,none,NULL¦end2_t¦#,none,NULL¦start3_t¦#,none,NULL¦end3_t¦#,none,NULL¦contact¦',none,''¦phone2¦',none,''¦office¦',none,''¦email¦',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "¦")
MM_columns = Split(MM_columnsStr, "¦")
' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
In order to get the syntax for the "dupe check" create a new recordset, a simple one to read from the calendar table. Then, you will modify the "WHERE" portion with:
WHERE tblEvent.Field ='" & Request("field to check") & "'"
That will be the clue to whether it already exists. You would put all that recordset code.....
If (CStr(Request("MM_insert")) <> "") Then
HERE
if above RecordSet NOT EOF then
stop processing here
else continue below
MM_editConnection = MM_dsnCoe_STRING
MM_editTable = "tblEvents"
MM_editRedirectUrl = "add_review.asp"
MM_fieldsStr = "publishedŠvalueŠlisttypeŠvalueŠtitle
be sure to add an "END IF" after the insert code
good luck with it. I'm sure you'll figure it out. Once you get comfortable with SQL and ASP commands you'll be able to do all the coding without needing Dreamweaver.
BTW...I know it doesn't matter, but I only actually have Dreamweaver and not UltraDev. I know the code is in UltraDev but I purchased the source code and the code did not come with development assistance.
Thanks again!
Since I don't have UltraDev and just Dreamweaver 4, I tried looking up the appropriate way to code how to create the recordset (see I told you I was green). I believe I found how to do this manually, but I'm getting errors (HTTP 500 error page). I know there is a way to turn off this friendly message and get to the root of the problem, but my company's IMS department has limited everyone's internet option abilities. I could look into changing this for our department but it would be alot of red tape. Anyways, I can't see why I'm getting the error so if you or anyone else for that matter can see what I'm doing it would be great. Here's the code:
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) <> "") Then
Dim rsstart1
Set rsstart1 = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT start1 from tblEvents WHERE tblEvents.field = '" & Request("start1") & "';"
rsstart1.Open strSQL, db
If Not rsstart1.EOF Then response.write "This room has been already reserved for this time, please select another time, room, or date."
Else
MM_editConnection = MM_dsnCoe_STRING
MM_editTable = "tblEvents"
MM_editRedirectUrl = "add_review.asp"
MM_fieldsStr = "published¦value¦listtype¦value¦title¦value¦category¦value¦Location¦value¦description¦value¦start1¦value¦end1¦value¦start2¦value¦end2¦value¦start3¦value¦end3¦value¦start1_t¦value¦end1_t¦value¦start2_t¦value¦end2_t¦value¦start3_t¦value¦end3_t¦value¦contact¦value¦phone2¦value¦office¦value¦email¦value"
MM_columnsStr = "published¦',none,''¦listtype¦',none,''¦title¦',none,''¦category¦',none,''¦Location¦',none,''¦description¦',none,''¦start1¦#,none,NULL¦end1¦#,none,NULL¦start2¦#,none,NULL¦end2¦#,none,NULL¦start3¦#,none,NULL¦end3¦#,none,NULL¦start1_t¦#,none,NULL¦end1_t¦#,none,NULL¦start2_t¦#,none,NULL¦end2_t¦#,none,NULL¦start3_t¦#,none,NULL¦end3_t¦#,none,NULL¦contact¦',none,''¦phone2¦',none,''¦office¦',none,''¦email¦',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "¦")
MM_columns = Split(MM_columnsStr, "¦")
' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
End If
%>
THANKS SO MUCH!
If (CStr(Request("MM_insert")) <> "") Then
Dim rsstart1
Set rsstart1 = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT start1 from tblEvents WHERE tblEvents.start1 = '" & Request("start1") & "';"
rsstart1.Open strSQL, db
If Not rsstart1.EOF Then response.write "This room has been already reserved, please select another time, room, or date."
Else
MM_editConnection = MM_dsnCoe_STRING
Here's the error message:
ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/keenanassoc/res2/addevent.asp, line 26
The Code:
17 <%
18' *** Insert Record: set variables
19
20 If (CStr(Request("MM_insert")) <> "") Then
21 Dim rsstart1
22 Set rsstart1 = Server.CreateObject("ADODB.Recordset")
23 strSQL = "SELECT start1 from tblEvents WHERE tblEvents.start1= '" & Request("start1") & "';"
24 rsstart1.Open strSQL, db
25 If Not rsstart1.EOF Then response.write "This room has been already reserved, please select another time, room, or date."
26 Else
MM_editConnection = MM_dsnCoe_STRING
MM_editTable = "tblEvents"
MM_editRedirectUrl = "add_review.asp"
MM_fieldsStr = "published¦value¦listtype¦value¦title¦value¦category¦value¦Location¦value¦description¦value¦start1¦value¦end1¦value¦start2¦value¦end2¦value¦start3¦value¦end3¦value¦start1_t¦value¦end1_t¦value¦start2_t¦value¦end2_t¦value¦start3_t¦value¦end3_t¦value¦contact¦value¦phone2¦value¦office¦value¦email¦value"
MM_columnsStr = "published¦',none,''¦listtype¦',none,''¦title¦',none,''¦category¦',none,''¦Location¦',none,''¦description¦',none,''¦start1¦#,none,NULL¦end1¦#,none,NULL¦start2¦#,none,NULL¦end2¦#,none,NULL¦start3¦#,none,NULL¦end3¦#,none,NULL¦start1_t¦#,none,NULL¦end1_t¦#,none,NULL¦start2_t¦#,none,NULL¦end2_t¦#,none,NULL¦start3_t¦#,none,NULL¦end3_t¦#,none,NULL¦contact¦',none,''¦phone2¦',none,''¦office¦',none,''¦email¦',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "¦")
MM_columns = Split(MM_columnsStr, "¦")
' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
Request("start1") should be in the access database as e.g. (03/28/03)--date/time and tblEvents.start1 should be...?
What would be your suggestion on how to solve this conflict? Do I need to use # in my database...a random thought.
That error may also mean the date is invalid. If you use two digits for the year or month part it allows it to be interpreted incorrectly by the database.
Better to use dd-mmm-yyyy
Some info on dates and ASP here
[aspfaq.com...]
I'M GOING BONKERS. THE CODE I HAVE IS GREAT, BUT I NEED TO PREVENT USERS FROM CREATING MULTIPLE RESERVATIONS FOR THE SAME ROOM, AT THE SAME TIME AND DATE. I'M ALSO TRYING TO PREVENT OVERLAPPING. IS THERE AN EASIER WAY TO DO THIS. SHOULDN'T THIS BE PRETTY SIMPLE?
YOUR HELP WOULD BE MUCH APPRECIATED!
You have all the pieces you need already, just keep tinkering with it until it works.
(I feel like Ellery Queen!)
You don't put the hash marks in the DB, you put them in your SQL statement
WHERE table.myDateField = #2/3/2003#
or, in your case since you are using variables:
myDate = 2/3/2003
mydate = "#" & mydate & "#"
WHERE table.myDateField = mydate
It look like you wanted to declare it. I have even do this statement: "SELECT start1 from tblEvents
WHERE start1 = "#" & 05/18/2003 & "#";"
Anything else you can suggest or point me to an example?
Anything else you can suggest or point me to an example?
WHERE start1 = "#05/18/2003#";"
The Hash marks are part of the date. Just try it with a fixed date rather than a variable to see that it works.
Then substitue the parameter.
It's a process.
A great tutorial for all things ASP can be found at www.w3schools.com. I've learned a great deal from them.
The problem you're running into is two fold: Access has a funny syntax sometimes (using the # for dates for example) and your UltraDev code has a lot of extraneous spaghetti.
I think you'll do fine.