By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

Update Record Issue - Please Help

P: 85
Hi CroCrew et All,

I am working on a project that will allow user to search for their opened projects (means the CompleteDate is NULL) and be able to update their WorkDescription. Once the record (ProjectID) is created, user can search for their opened projects using either their Username or ProjectID ok without problem because the CompleteDate is NULL at this time. One thing here is when you use your Username you can only search for opened projects and when you use the ProjectID you can search either closed project (means the CompleteDate is filled ex. 2/1/2008) and opened projects (means the field is NULL).

The issue that I have here as soon as the User updates their WorkDescription (just the WorkDescription field and WITHOUT put in the CompleteDate because the project is not completed yet), it will allow the User update OK however, when he/she goes back and searches by their Username again, the project that they just UPDATED does not show up anymore even though there is nothing in the CompleteDate.

The thing here is when you remove the CompleteDate from the UpdateProject.asp file, there will be no problem. It looks to me like when you click on the Update button, something still sent to the CompleteDate field knowing that the User hasn't put in the completedate yet that makes my search script thing that the Project is NOT NULL anymore that's why they can't search anymore. Thanks for your help.

Here is the CompleteDate field defined in the MS Access database:

FieldName: Text
Field Size: 50
Required: No
Allow Zero Length: Yes
Indexed: No

Here is the UpdateProject.asp file:

Dim strGDNIEngineer
Dim strCompleteDate
Dim strWorkDescription

Dim adocon
Dim strSQL

ProjectID = Request.Form("ProjectID")
strGDNIEngineer = trim(Request.Form("GDNIEngineer"))
strCompleteDate = trim(Request.Form("CompleteDate"))
strWorkDescription = trim(Request.Form("WorkDescription"))

If ProjectID <> "" Then
Set adocon = Server.CreateObject("ADODB.Connection")

adocon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("PTSystem.mdb")

strSQL = "UPDATE PTSProjects SET CompleteDate = '"& strCompleteDate &"', WorkDescription = '"& strWorkDescription &"'"
strSQL = strSQL & " WHERE ProjectID = " & ProjectID

Set adocon = Nothing

When you click the Search button, it will then call the DisplayProject.asp file to display the search. Here is the DisplayProject.asp file SEARCH ONLY PORTION.

Dim strGDNIEngineer
Dim strCompleteDate
Dim Conn
Dim strSQL
Dim RS

strGDNIEngineer = trim(Request.Form("GDNIEngineer"))
strCompleteDate = trim(Request.Form("CompleteDate"))
If len(strGDNIEngineer)=0 then
End if

Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.Recordset")

Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("PTSystem.mdb")

If isNumeric(strGDNIEngineer) then
strSQL = "Select * FROM PTSProjects WHERE ProjectID=" & strGDNIEngineer
if strGDNIEngineer="ALL OPENED PROJECTS" then
strSQL = "Select * FROM PTSProjects WHERE CompleteDate IS NULL"' ORDER BY ProjectID'
strSQL = "Select * FROM PTSProjects WHERE GDNIEngineer='" & strGDNIEngineer & "' AND CompleteDate IS NULL"' ORDER BY ProjectID'
end if
End If

RS.Open strSQL, Conn

If RS.EOF Then
Response.Redirect("SearchProject.asp?error=Sorry ... Your Project ID does not exist in our database. Please try again.")
End If
Feb 1 '08 #1
Share this Question
Share on Google+
8 Replies

Expert 100+
P: 979
Hi hotflash,

In the scenario you described the user wants to update the WorkDescription and leave the CompleteDate null. I think the problem might be that when the user doesn't enter a CompleteDate you are passing "" into your query as the variable strCompleteDate. "" is not the same as NULL so when you update your record the database changes from NULL to "" and your second query doesn't pick the record up

A possible solution would be to add an If..Then before updating the CompleteDate to check if anything has been entered for it.

Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE PTSProjects SET " 
  3. If strCompleteDate <> "" Then
  4.      strSQL = strSQL & " CompleteDate = '" & strCompleteDate & "', "
  5. End If
  7. strSQL = strSQL & " WorkDescription = '"& strWorkDescription &"' "
  8. strSQL = strSQL & " WHERE ProjectID = " & ProjectID
  9. adocon.Execute(strSQL)
I hope that this helps to sort your problem out. Let me know how it goes.

Dr B
Feb 1 '08 #2

P: 85
Hi DrB,

Thanks for your outstanding recommendation. THING WORKS AS DESIGNED.

However, I ran into a minor problem. The issue is, if you put in the CompleteDate let's say, 2/1/2008, it will UPDATE OK and you can no longer search for the project because it is consider CLOSED. Which is OK.

If I go back and REOPEN it by removing the CompleteDate, and click UPDATE, it does not REMOVE the CompleteDate. I thought if you remove the CompleteDate, the project will consider OPENED because the CompleteDate becomes NULL again. Please help. Thanks.
Feb 1 '08 #3

Expert 100+
P: 563
Hello hotflash,

The two values (NULL and “”) are not the same. Many people make this mistake it thinking they are. Logically speaking it seems that it would serve you better if you had another field within your database that would answer your query in if the “project” was open or closed. A boolean field (true or false) that you could switch on or off really would be more efficient too.

Hope that helps~
Feb 2 '08 #4

P: 85
Hi CroCrew,

Your new method sounds good but it is over my head since I am new to this stuff unless you can give me example to follow.

If you look at my reply to DrB, I got it work that way too but the only show stopper now is let's say if I fill out a completedate let's say 2/2/2008, of course, I won't be able to search for opened project anymore because this is consider closed. However, if I REMOVE the completedate to make it blank, for some reason the date still stay in the CompleteDate field. I thought when you do that, the fill will become BLANK again.

Please advise and thanks once again for your help.
Feb 3 '08 #5

Expert 100+
P: 563
Hello hotflash,

Can you show us your code that you are using to removed the date. That might help.

What I was saying was to create another field in your database that stores a value of true or false. Call that field something like ‘Completed’ and just update that field to determine if the record is completed or not rather then using a date field.

Have fun~
Feb 3 '08 #6

P: 85
Hi CroCrew,

I just go into MS Access and remove the CompleteDate manually. Because if there is a need to reopen a record, instead of opening a new one, I just want to get into the database, remove the CompleteDate to make the record becomes OPENED again. When you have a chance to look at the Search using Case method instead of Nested IF, can you include the search for GDNIEngineer and OPENED records (CompleteDate is blank)? Thanks for your outstanding support.
Feb 4 '08 #7

P: 85
Hi Master CroCrew,

Sorry for the confusion. I have too much going on that's why don't remember the issue. If I manually remove the field in the database then it will search fine for the OPENED RECORDS, what actually does not work is when I search for a closed record, REMOVE the CompleteDate field, the script does not allow me to update the CompleteDate field to make it becomes "BLANK". Thanks for your help.
Feb 4 '08 #8

Expert 100+
P: 563
Hello hotflash,

Take a look at the full running example I sent you. I think you will get a better understanding after looking at it.

After extracting the files make sure that you check your permissions on appropriate .mdb file and its directory, set them to read-write for the ISUR user that your site is using.

This example uses a two page process Example.asp and Post_Update.asp Make sure you take a look at the attached database to see how the tables are set up. Password to the database is “happy” (without the quotes).

Hope this helps~

For others that might want to see what I had sent hotflash here is the code:

Expand|Select|Wrap|Line Numbers
  1. -Field Name-, -Data Type-
  2. KeyId, AutoNumber
  3. Completed, Yes/No
  4. FieldOne, Text
  5. FieldTwo, Text
  6. FieldThree, Text
  7. CompletedDate, Text
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Set Conn = Server.CreateObject("ADODB.Connection")
  3.     Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Database.mdb") & "; Jet OLEDB:Database Password=happy"
  4.     Set myRS = Server.CreateObject("ADODB.Recordset")
  5.     SQL = "SELECT * FROM TheTable"
  6.     myRS.CursorType = 1
  7.     myRS.LockType = 3
  8.     myRS.Open SQL, Conn
  9. %>
  10. <html>
  11.     <head>
  12.         <title>Example</title>
  13.     </head>
  14.     <body>
  15.         <table border="0">
  16.             <%If (Request.Querystring("UpdatedRecord")) Then%>
  17.                 <tr><td colspan="6" align="center"><font color="#FF0000"><b>Record has been updated!</b></font></td></tr>
  18.             <%End If%>
  19.             <tr>
  20.                 <td>Completed</td>
  21.                 <td>Field One</td>
  22.                 <td>Field Two</td>
  23.                 <td>Field Three</td>
  24.                 <td>Completed Date</td>
  25.                 <td>&nbsp;</td>
  26.             </tr>
  27.             <%i=1%>
  28.             <%Do Until (myRS.EOF)%>
  29.                 <form method="post" action="Post_Update.asp" name="xform<%=i%>">
  30.                     <input type="hidden" name="RecordKeyID" value="<%Response.Write(myRS("KeyID"))%>">
  31.                     <tr>
  32.                         <td align="center"><input type="checkbox" name="xCompleted" value="true"<%If (myRS("Completed")) Then%> checked<%End If%>></td>
  33.                         <td><input type="text" name="xFieldOne" value="<%Response.Write(myRS("FieldOne"))%>"></td>
  34.                         <td><input type="text" name="xFieldTwo" value="<%Response.Write(myRS("FieldTwo"))%>"></td>
  35.                         <td><input type="text" name="xFieldThree" value="<%Response.Write(myRS("FieldThree"))%>"></td>
  36.                         <td><input type="text" name="xCompletedDate" value="<%Response.Write(myRS("CompletedDate"))%>"></td>
  37.                         <td><input type="submit" value="Update"></td>
  38.                     </tr>
  39.                 </form>
  40.                 <%i=(i+1)%>
  41.                 <%myRS.MoveNext%>
  42.             <%Loop%>
  43.         </table>
  44.     </body>
  45. </html>
  46. <%
  47.     myRS.close
  48.     Conn.close
  49. %>
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Set Conn = Server.CreateObject("ADODB.Connection")
  3.         Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Database.mdb") & "; Jet OLEDB:Database Password=happy"
  4.     Set rsUpdate = Server.CreateObject("ADODB.Recordset")
  5.     SQL = "SELECT * FROM TheTable WHERE KeyID = " & Request.Form("RecordKeyID")
  6.     rsUpdate.CursorType = 1
  7.     rsUpdate.LockType = 3
  8.     rsUpdate.Open SQL, Conn
  10.     If (Request.Form("xCompleted")) Then
  11.         rsUpdate.Fields("Completed") = "true"
  12.     Else
  13.         rsUpdate.Fields("Completed") = "false"
  14.     End If
  15.     rsUpdate.Fields("FieldOne") = Request.Form("xFieldOne")
  16.     rsUpdate.Fields("FieldTwo") = Request.Form("xFieldTwo")
  17.     rsUpdate.Fields("FieldThree") = Request.Form("xFieldThree")
  18.     rsUpdate.Fields("CompletedDate") = Request.Form("xCompletedDate")
  20.     rsUpdate.Update    
  21.     rsUpdate.close
  22.     Conn.close
  24.     Response.Redirect("Example.asp?UpdatedRecord=true")
  25. %>
Feb 4 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.