473,549 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update Record Issue - Please Help

85 New Member
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.a sp 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.a sp file:

<%
Dim strGDNIEngineer
Dim strCompleteDate
Dim strWorkDescript ion

Dim adocon
Dim strSQL

ProjectID = Request.Form("P rojectID")
strGDNIEngineer = trim(Request.Fo rm("GDNIEnginee r"))
strCompleteDate = trim(Request.Fo rm("CompleteDat e"))
strWorkDescript ion = trim(Request.Fo rm("WorkDescrip tion"))

If ProjectID <> "" Then
Set adocon = Server.CreateOb ject("ADODB.Con nection")

adocon.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & Server.MapPath( "PTSystem.m db")

strSQL = "UPDATE PTSProjects SET CompleteDate = '"& strCompleteDate &"', WorkDescription = '"& strWorkDescript ion &"'"
strSQL = strSQL & " WHERE ProjectID = " & ProjectID
adocon.Execute( strSQL)

adocon.Close
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.Fo rm("GDNIEnginee r"))
strCompleteDate = trim(Request.Fo rm("CompleteDat e"))
If len(strGDNIEngi neer)=0 then
strGDNIEngineer =0
End if

Set Conn = Server.CreateOb ject("ADODB.Con nection")
Set RS = Server.CreateOb ject("ADODB.Rec ordset")

Conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & Server.MapPath( "PTSystem.m db")

If isNumeric(strGD NIEngineer) then
strSQL = "Select * FROM PTSProjects WHERE ProjectID=" & strGDNIEngineer
Else
if strGDNIEngineer ="ALL OPENED PROJECTS" then
strSQL = "Select * FROM PTSProjects WHERE CompleteDate IS NULL"' ORDER BY ProjectID'
else
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.Redire ct("SearchProje ct.asp?error=So rry ... Your Project ID does not exist in our database. Please try again.")
End If
%>
Feb 1 '08 #1
8 1576
DrBunchman
979 Recognized Expert Contributor
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 " 
  2.  
  3. If strCompleteDate <> "" Then
  4.      strSQL = strSQL & " CompleteDate = '" & strCompleteDate & "', "
  5. End If
  6.  
  7. strSQL = strSQL & " WorkDescription = '"& strWorkDescription &"' "
  8. strSQL = strSQL & " WHERE ProjectID = " & ProjectID
  9. adocon.Execute(strSQL)
  10.  
I hope that this helps to sort your problem out. Let me know how it goes.

Dr B
Feb 1 '08 #2
hotflash
85 New Member
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
CroCrew
564 Recognized Expert Contributor
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
hotflash
85 New Member
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
CroCrew
564 Recognized Expert Contributor
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
hotflash
85 New Member
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
hotflash
85 New Member
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
CroCrew
564 Recognized Expert Contributor
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:

Database:
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
  8.  
Example.asp
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. %>
  50.  
Post_Update.asp
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
  9.  
  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")
  19.  
  20.     rsUpdate.Update    
  21.     rsUpdate.close
  22.     Conn.close
  23.  
  24.     Response.Redirect("Example.asp?UpdatedRecord=true")
  25. %>
  26.  
Feb 4 '08 #9

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

Similar topics

0
2770
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get it from the db table is: ''Retrieve the Registration Identification Number strRegisterID = Rs("Register_ID") Prior to testing my code and actually...
5
2345
by: A.Dagostino | last post by:
hi i need to update an SQL Table when user select or unselect a checkbox control. How Can i do? Thanks Alex
16
16980
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then...
4
26160
by: N. Graves | last post by:
Hello... thank you for your time. I have a form that has a List box of equipotent records and a sub form that will show the data of the equipment select from the list box. Is it possible to make a change in the name field in the details, then refresh the list box with new name? Please help and thanks!
29
2102
by: Geoff Jones | last post by:
Hi All I hope you'll forgive me for posting this here (I've also posted to ado site but with no response so far) as I'm urgently after a solution. Can anybody help me? I'm updating a table on a database i.e. I've modified the table in a DataSet and I want to update it to the SQL database which the table originally came from. I'm using a...
5
3524
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I do the update the changed parentid in the child table fails to change. No error is given its just that the change is not written to the Database. ...
16
3798
by: vbnetdev | last post by:
hi all, This code works to add a nameserver to a container in DNS using vb.net and WMI. Howeer the code below that to add host records such as WWW and to add an MX record does not. It ojects with "invalid path" complaints. Any ideas what I am doing wrong? This is vb.net 2005 and the platform is Windows Server 2003 SP1. 'code works Dim...
17
2512
by: michel.ank | last post by:
Hi, I'm using the class PrintLines and my last record of page aren't with the borders. Somebody can help me? Thanks,
2
3868
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously stated. Also please note that this is unrelated to another of my previous threads, “dataAdapter.Update problem”, which incidentally has been resolved. ...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7469
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.