Hi everyone
I have a little problem in updating a record. I know how add a new record and check if the inputted new data is existing or not as what they have discussed in http://www.thescripts.com/forum/thread733529.html.
Now, my problem is... How can I check if updating data is existing or not? Please help!!!
Here's my sample code in adding a new entry:
[CODE=vb]Public dbConnection As New ADODB.Connectio n
Dim dbPath As String
dbPath = App.Path & "\Database\Cour ses.mdb"
[/CODE]
-------------------------------------------------------------------------------------------------------------------
[CODE=vb]
Public Sub SetConnection()
Set dbConnection = New ADODB.Connectio n
dbConnection.Op en "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & dbPath & _
";Persist Security Info=False"
End Sub
[/CODE]
-------------------------------------------------------------------------------------------------------------------
[CODE=vb]
Public Function CheckConnection (adRecordset As ADODB.Recordset )
If adRecordset.Sta te = 1 Then adRecordset.Clo se
End Function
[/CODE]
[CODE=vb]Public Function Duplicate(ByRef adConnection As ADODB.Connectio n, ByRef adRecordset As _
ADODB.Recordset , StrSQL As String, ByVal Title As String) As Boolean
'Default value
Duplicate = False
'Opens and checks the connection
SetConnection
CheckConnection adRecordset
adRecordset.Ope n StrSQL & Title & "'", _
dbConnection, 1, 1
'Checks if there is duplicate title
If adRecordset.Rec ordCount > 0 Then
Duplicate = True
Else
Duplicate = False
End If
End Function
[/CODE]
[CODE=vb]Dim str As String
str = "Select Course.Title From Courses"
If Duplicate(con, rs, str, txtCourse.Text) = False Then
rs.Open "Insert Into ([Course]) Values ('" & txtCourse.Text & "')", dbConnection, 3, 3
Else
Msgbox "Duplicatio n is not allowed.", 48
End If[/CODE]
I have a little problem in updating a record. I know how add a new record and check if the inputted new data is existing or not as what they have discussed in http://www.thescripts.com/forum/thread733529.html.
Now, my problem is... How can I check if updating data is existing or not? Please help!!!
Here's my sample code in adding a new entry:
[CODE=vb]Public dbConnection As New ADODB.Connectio n
Dim dbPath As String
dbPath = App.Path & "\Database\Cour ses.mdb"
[/CODE]
-------------------------------------------------------------------------------------------------------------------
[CODE=vb]
Public Sub SetConnection()
Set dbConnection = New ADODB.Connectio n
dbConnection.Op en "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & dbPath & _
";Persist Security Info=False"
End Sub
[/CODE]
-------------------------------------------------------------------------------------------------------------------
[CODE=vb]
Public Function CheckConnection (adRecordset As ADODB.Recordset )
If adRecordset.Sta te = 1 Then adRecordset.Clo se
End Function
[/CODE]
[CODE=vb]Public Function Duplicate(ByRef adConnection As ADODB.Connectio n, ByRef adRecordset As _
ADODB.Recordset , StrSQL As String, ByVal Title As String) As Boolean
'Default value
Duplicate = False
'Opens and checks the connection
SetConnection
CheckConnection adRecordset
adRecordset.Ope n StrSQL & Title & "'", _
dbConnection, 1, 1
'Checks if there is duplicate title
If adRecordset.Rec ordCount > 0 Then
Duplicate = True
Else
Duplicate = False
End If
End Function
[/CODE]
[CODE=vb]Dim str As String
str = "Select Course.Title From Courses"
If Duplicate(con, rs, str, txtCourse.Text) = False Then
rs.Open "Insert Into ([Course]) Values ('" & txtCourse.Text & "')", dbConnection, 3, 3
Else
Msgbox "Duplicatio n is not allowed.", 48
End If[/CODE]
Comment