fafa
Posts: 27
|
Posted: 04/17/2004, 10:08 AM |
|
The following is the Record form’s OnValidate event,
Dim IsUniqueValue
If NOT (projects_emp_rec.EditMode) Or (CCGetFromGet("project_id",0) <> CCGetFromPost("project_id",0) Or CCGetFromGet("emp_id",0) <> CCGetFromPost("emp_id",0)) Then
IsUniqueValue = CCDLookUp("project_id", "projects_employees", "project_id="&DBIntranetDB.ToSQL(CCGetFromPost("project_id",0),ccsInteger)&" AND emp_id="&DBIntranetDB.ToSQL(CCGetFromPost("emp_id",0),ccsInteger), DBIntranetDB)
If IsUniqueValue Then
projects_emp_rec.Errors.AddError("The project is already assigned to this employee.")
End if
End if
1) I don't understand the above coding?
2) How to use "CCGetFromGet" and "CCGetFromPost"?
|
|
|
peterr
Posts: 5971
|
Posted: 04/17/2004, 12:21 PM |
|
1. If the form is in Insert mode (not Edit) or submitted key values are different from search parameters (in case the user changed the values and submitted new ones) then lookup the key values in the database to check if they already exist. If they do exist then display the appropriate error.
2. CCGetFromGet and CCGetFromPost retrieve the value of GET (URL) and POST (form) fields, respectively. The first parameter is the name of the GET or POST field that you want to read. The second parameter is the default value in case such field doesn't exist in GET or POST.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
fafa
Posts: 27
|
Posted: 04/17/2004, 1:30 PM |
|
THANKS, peterr
But I don't understand the following statement.
"project_id="&DBIntranetDB.ToSQL(CCGetFromPost("project_id",0),ccsInteger)
|
|
|
peterr
Posts: 5971
|
Posted: 04/17/2004, 1:35 PM |
|
This is part of the WHERE statement for the lookup. It checks if the database already contains the project_id equal to the one submitted (POSTed) by the user via the record form: CCGetFromPost("project_id",0)
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
fafa
Posts: 27
|
Posted: 04/18/2004, 3:09 AM |
|
THANKS AGAIN, peterr
I have another problem. When I modify the code but it does not work. What is the problem on my coding?
I have a table (appointment) with three fields (appointment_date, time_id, doctor_id)
My Code:
IsUniqueValue = CCDLookUp("doctor_id", "appointment", "project_id="&DBdatabase.ToSQL(CCGetFromPost("appointment_date",0),ccsdate)&" AND time_id="&DBdatabase.ToSQL(CCGetFromPost("time_id",0),ccsInteger)&" AND doctor_id="&DBdatabase.ToSQL(CCGetFromPost("doctor_id",0),ccsInteger), DBIntranetDB)
|
|
|
peterr
Posts: 5971
|
Posted: 04/18/2004, 2:09 PM |
|
I'd like to get more details on the "does not work" part
Are you seeing any errros?
But one thing that doesn't look right is that you're comparing the "project_id" in the database to "appointment_date" submitted by the users.
..."project_id="&DBdatabase.ToSQL(CCGetFromPost("appointment_date",0),ccsdate)...
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
fafa
Posts: 27
|
Posted: 04/19/2004, 6:50 AM |
|
Dim IsUniqueValue
If NOT (appointment.EditMode) Or (CCGetFromGet("doctor_id",0) <> CCGetFromPost("doctor_id",0) Or CCGetFromGet("appointment_date",0) <> CCGetFromPost("appointment_date",0) Or CCGetFromGet("timezone_id",0) <> CCGetFromPost("timezone_id",0)) Then
IsUniqueValue = CCDLookUp("doctor_id", "appointment", "doctor_id="&DBdatabase.ToSQL(CCGetFromPost("doctor_id",0),ccsInteger)&" AND appointment_date="&DBdatabase.ToSQL(CCGetFromPost("appointment_date",0),ccsDate)&" AND timezone_id="&DBdatabase.ToSQL(CCGetFromPost("timezone_id",0),ccsInteger), DBIntranetDB)
If IsUniqueValue Then
appointment.Errors.AddError("The doctor is already assigned.")
End if
End if
I can't see any errors during execution. It doesn't show an error message when I input the duplicated appointment record.
I am using ACCESS 2000 and ASP 3.0
Field Data Type
==========================
doctor_id Integer
appointment_date Date
timezone_id Integer
Is any error on my coding?
|
|
|
fafa
Posts: 27
|
Posted: 04/20/2004, 11:34 AM |
|
Hi peterr,
I see an error message 'Database command error' . It can't show the customer message.
|
|
|
peterr
Posts: 5971
|
Posted: 04/20/2004, 12:52 PM |
|
Is "IntranetDB" the name of your database connection? If not, change "DBIntranetDB" to "DBsomethingelse".
But generally it is pretty difficult for anyone to debug your code without being able to run it. Only you can determine what doesn't work by debugging the code. If something doesn't work then please analyze every single value by printing it and checking if it looks OK.
See: http://docs.codecharge.com/studio/html/ProgrammingTechn...yingOutput.html
For example you can quickly do:
response.write CCDLookUp("doctor_id", "appointment", "doctor_id="&DBdatabase.ToSQL(CCGetFromPost("doctor_id",0),ccsInteger)
response.write DBdatabase.ToSQL(CCGetFromPost("timezone_id",0),ccsInteger)
and the same with all the other parts of your code and you will right away know what exactly doesn't work.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
fafa
Posts: 27
|
Posted: 04/21/2004, 7:59 AM |
|
Hi peterr, THANKS AGAIN
I had followed your suggestion.
I find the problem...
response.write ccgetfrompost("timezone",0)--->it returns "1"
response.write ccdlookup("doctor_id", "appointment", "timezone_id="&dbdatabasename.tosql(ccgetfrompost("timezone_id",0),ccsinteger),dbdabasename)---> it returns nothing
Therefore, the statement of "IsUniqueValue..." also returns nothing.
Any idea on my problem?
|
|
|
peterr
Posts: 5971
|
Posted: 04/21/2004, 12:29 PM |
|
Looks like you submitted the value "1" in the "timezone" field on your form. Is this a problem? Should it be a different value?
If so, then verify your HTML code and the configuration of your "timezone" field on your form.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
fafa
Posts: 27
|
Posted: 04/21/2004, 1:13 PM |
|
Hi peterr,
I can get the value from the 'timezone" field.
But I have another problem on CCGetFromGet and CCGetFromPost. CCGetFromGet and CCGetFromPost can retreive the value of GET (URL) and POST (form) fields. Is it possible to retreive all data type (i.e. integer, text, date...)?
Regards
|
|
|
peterr
Posts: 5971
|
Posted: 04/21/2004, 1:56 PM |
|
Yes, I think that both CCGetFromGet and CCGetFromPost can read any values that are being submitted. But it would be your decision to handle each value appropriately. Only you know if the value being submitted is numeric, text or date. Therefore you would need to decide if value "2" is a number or text, usually based on the type of the field that users entered it into.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
fafa
Posts: 27
|
Posted: 04/22/2004, 5:31 AM |
|
THANKS AGAIN, I can retrieve the date value via CCGetFromPost.
|
|
|
|