I have this code - Public Function Duplicate(ByRef adRecordset As ADODB.Recordset, ByRef Subject As _
-
String, ByRef Course As String) As Boolean
-
Duplicate = False 'Default value
-
-
'Opens and checks the connection
-
SetConnection
-
CheckConnection adRecordset
-
-
adRecordset.Open "Select SubjectCode From LoadSchedules Where SubjectCode='" & _
-
Subject & "' And Courses.Title='" & Course & "'", dbConnection, 1, 1
-
'Checks if there is duplicate subject
-
If adRecordset.RecordCount > 0 Then
-
Duplicate = True
-
Else
-
Duplicate = False
-
End If
-
Set dbConnection = Nothing
-
End Function
-
-
'====================================
-
-
Public Sub Update(ByVal ScheduleID As String, ByRef SubjectCode As String, ByRef _
-
Lecture As Integer, ByRef Laboratory As Integer, ByRef StartTime As Date, ByRef EndTime _
-
As Date, ByRef DayID As String, ByRef RoomID As String, adForm As Form)
-
'Opens and checks the connection
-
SetConnection
-
'CheckConnection adRecordset
-
-
-
'Update course
-
dbConnection.Execute "Update Schedules Set [SubjectCode]='" & SubjectCode & _
-
"',[Lecture]=" & Lecture & ",[Laboratory]=" & Laboratory & ",[StartTime]=#" & _
-
StartTime & "#,[EndTime]=#" & EndTime & "#,[DayID]='" & DayID & "'," & _
-
"[RoomID]='" & RoomID & "' Where [ScheduleID]='" & ScheduleID & "'"
-
Unload adForm
-
-
frmSchedules.LoadSchedules
-
MsgBox ScheduleID & " has been successfully updated.", 64, "Updated Schedule"
-
frmSchedules.LoadSchedules
-
Set dbConnection = Nothing
-
Exit Sub
-
-
-
End Sub
-
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
13 1190
...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?
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
This does nothing to help explain what you mean by "How can I update the schedule without prompting existing?".
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
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)
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?
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
How about using the following SQL statements?
Inserts "PE" and 5 in tblCourses if "PE" doesn't exist in tblCourses. -
INSERT INTO tblCourses ( Subject, Units )
-
SELECT DISTINCT "PE", 5
-
FROM tblCourses
-
WHERE "PE" NOT In (Select Subject From tblCourses);
Updates Units field if the subject is "PE". - UPDATE tblCourses SET Units = "1000"
-
WHERE Subject="PE";
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.
How about using the following SQL statements?
Inserts "PE" and 5 in tblCourses if "PE" doesn't exist in tblCourses. -
INSERT INTO tblCourses ( Subject, Units )
-
SELECT DISTINCT "PE", 5
-
FROM tblCourses
-
WHERE "PE" NOT In (Select Subject From tblCourses);
Updates Units field if the subject is "PE". - UPDATE tblCourses SET Units = "1000"
-
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
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?
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))
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))
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |