473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Updating subject

lotus18
866 512MB
I have this code

Expand|Select|Wrap|Line Numbers
  1. Public Function Duplicate(ByRef adRecordset As ADODB.Recordset, ByRef Subject As _
  2. String, ByRef Course As String) As Boolean
  3.     Duplicate = False 'Default value
  4.  
  5.     'Opens and checks the connection
  6.     SetConnection
  7.     CheckConnection adRecordset
  8.  
  9.     adRecordset.Open "Select SubjectCode From LoadSchedules Where SubjectCode='" & _
  10.     Subject & "' And Courses.Title='" & Course & "'", dbConnection, 1, 1
  11.     'Checks if there is duplicate subject
  12.     If adRecordset.RecordCount > 0 Then
  13.         Duplicate = True
  14.     Else
  15.         Duplicate = False
  16.     End If
  17.     Set dbConnection = Nothing
  18. End Function
  19.  
  20. '====================================
  21.  
  22. Public Sub Update(ByVal ScheduleID As String, ByRef SubjectCode As String, ByRef _
  23. Lecture As Integer, ByRef Laboratory As Integer, ByRef StartTime As Date, ByRef EndTime _
  24. As Date, ByRef DayID As String, ByRef RoomID As String, adForm As Form)
  25.     'Opens and checks the connection
  26.     SetConnection
  27.     'CheckConnection adRecordset
  28.  
  29.  
  30.     'Update course
  31.     dbConnection.Execute "Update Schedules Set [SubjectCode]='" & SubjectCode & _
  32.     "',[Lecture]=" & Lecture & ",[Laboratory]=" & Laboratory & ",[StartTime]=#" & _
  33.     StartTime & "#,[EndTime]=#" & EndTime & "#,[DayID]='" & DayID & "'," & _
  34.     "[RoomID]='" & RoomID & "' Where [ScheduleID]='" & ScheduleID & "'"
  35.     Unload adForm
  36.  
  37.     frmSchedules.LoadSchedules
  38.     MsgBox ScheduleID & " has been successfully updated.", 64, "Updated Schedule"
  39.     frmSchedules.LoadSchedules
  40.     Set dbConnection = Nothing
  41.     Exit Sub
  42.  
  43.  
  44. End Sub
  45.  

I use the duplicate function to check if the subject is already existing before the update function, now my problem is this, I can only update subject if modify it. How can I update the schedule without prompting existing? Hope you understand my post

Rey Sean
Jan 28 '08 #1
13 1190
Killer42
8,435 Expert 8TB
...I use the duplicate function to check if the subject is already existing before the update function, now my problem is this, I can only update subject if modify it. How can I update the schedule without prompting existing? Hope you understand my post
Um... could you try to explain a bit further what you want to do? I don't see any "prompting" there, only a notification that "blah was updated".

And what version of VB are you using?
Jan 29 '08 #2
lotus18
866 512MB
Hi Killer

Sorry for lack of information, I call that function on another form, then when the user click Save, then if the duplicate = true then a messagebox will de displayed.

Rey Sean
Jan 29 '08 #3
Killer42
8,435 Expert 8TB
This does nothing to help explain what you mean by "How can I update the schedule without prompting existing?".
Jan 29 '08 #4
debasisdas
8,127 Expert 4TB
What do you mean by I can only update subject if modify it. You need to call the update procedure only if duplicate function returns false. What is this line of code doing .

frmSchedules.LoadSchedules
Jan 29 '08 #5
lotus18
866 512MB
What do you mean by I can only update subject if modify it. You need to call the update procedure only if duplicate function returns false.
How can I call the update procedure if the didn't modify the item? It is better to give an example than to explain : )

E.g.

Existing records

Subjects Units
-Math 3.0
-English 5.0
-History 2.0

Then I chose Math to modify, but I change only its units not the subject, then the duplicates now becomes true because Math is already existed.


What is this line of code doing .

frmSchedules.LoadSchedules
This populates the list of schedules on a listview (refresh the items)
Jan 29 '08 #6
Killer42
8,435 Expert 8TB
So are you saying that if the subject is changed you want to create a new record, and if it isn't, you want to update the existing record?
Jan 29 '08 #7
lotus18
866 512MB
So are you saying that if the subject is changed you want to create a new record, and if it isn't, you want to update the existing record?
I just want to update existing record
Jan 30 '08 #8
How about using the following SQL statements?

Inserts "PE" and 5 in tblCourses if "PE" doesn't exist in tblCourses.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblCourses ( Subject, Units )
  2.    SELECT DISTINCT "PE", 5
  3.    FROM tblCourses
  4.    WHERE "PE" NOT In (Select Subject From tblCourses);
Updates Units field if the subject is "PE".

Expand|Select|Wrap|Line Numbers
  1. UPDATE tblCourses SET Units = "1000"
  2. WHERE Subject="PE";
Jan 31 '08 #9
Killer42
8,435 Expert 8TB
It sounds to me as though you need to have a primary key that you can use to refer to the records, so that you're not dependent on the subject to find them.
Jan 31 '08 #10
lotus18
866 512MB
How about using the following SQL statements?

Inserts "PE" and 5 in tblCourses if "PE" doesn't exist in tblCourses.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblCourses ( Subject, Units )
  2.    SELECT DISTINCT "PE", 5
  3.    FROM tblCourses
  4.    WHERE "PE" NOT In (Select Subject From tblCourses);
Updates Units field if the subject is "PE".

Expand|Select|Wrap|Line Numbers
  1. UPDATE tblCourses SET Units = "1000"
  2. WHERE Subject="PE";
I have no problem for inserting a record. I can detect if the record (subject) is already exist before it saves. It would prompt me that new record is already exist. For updating, I can update subject same as the statement as you given above, but my question is how can I update without prompting that the record is already existing? I know that I have to remove the Duplicate Function before the Update. Refer to my post at #6. Is there any other way how to this?

BTW, I think I've got an idea from the other forum and try it later (I have to do homeworks and study my lessons coz we'll be having a quiz by tomorrow). Maybe I can post here the updates... Thanks for your time : )

Rey Sean
Jan 31 '08 #11
Killer42
8,435 Expert 8TB
I think what you need is a smarter duplicate-detection routine which doesn't consider the current record as a duplicate.

In other words, you need to be able to ask it "are there any records other than this one with this subject?". That's where the primary key comes in. You pass the relevant (possibly duplicated) details, and the key of the record you're about to update. The routine checks for the existence of any record which matches the relevant detail(s) and doesn't have the same key.

Does this sound reasonable?
Feb 1 '08 #12
lotus18
866 512MB
I think what you need is a smarter duplicate-detection routine which doesn't consider the current record as a duplicate.

In other words, you need to be able to ask it "are there any records other than this one with this subject?". That's where the primary key comes in. You pass the relevant (possibly duplicated) details, and the key of the record you're about to update. The routine checks for the existence of any record which matches the relevant detail(s) and doesn't have the same key.

Does this sound reasonable?
Yes you're right, having a PK it prevents duplication of records. But the thing is, what if my professor would like to change the record (just thinking for his possible questions haha)? I did this by setting the general properties of the field in access (Indexed Yes > (Duplicates OK))
Feb 1 '08 #13
lotus18
866 512MB
I did this by setting the general properties of the field in access (Indexed Yes > (Duplicates OK))

Sorry for the trouble guys, this should be (Indexed Yes > (No Duplicates))
Feb 1 '08 #14

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

Similar topics

2
by: Denrael | last post by:
I am looking for a way in Python to update Windows File Summary Metadata. By that I mean the data (Title, Subject, Keywords, Comments) found when you right click a windows file, select properties...
1
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass...
3
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data...
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
1
by: atulsaxena1981 | last post by:
I want to modify the details (like subject, description, st. date, end date etc.) of a particular appointment from SQL Server 2005 on the basis of ID. As now I am writing this code but this would...
1
by: raknin | last post by:
Hi, I am looking for code example or article that explains how can I refresh part of a screen that contains links and description. I want every time that the user perform new search or additional...
1
by: Edwin.Madari | last post by:
by the way, iterating over bar will throw KeyError if that key does not exist in foo. to see that in action, simply set another key in bar after copy.deepcopy stmt in this example.. bar = 0 and...
2
by: =?Utf-8?B?TUNN?= | last post by:
I have an asp.net page that contains an update panel. Within the update panel, controls get added dynamically. During partial page post backs the controls within the panel will change. I have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.