Problem for update data.

Fztay

New member
Local time
Yesterday, 22:33
Joined
May 7, 2014
Messages
3
I have the following code under save button.It works well but the problem is that I can not update data.If I try to update data it shows duplicate data not allowed.What type of code need to update data of Form1.After the save button I also show my update code.--

Private Sub Save_Button()
Dim dbs As Database, rs As Recordset, iNewID As Integer

iNewID = Nz(DMax("[SL_No]", "Form1"), 0) + 1

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("SELECT * FROM Form1")
rs.AddNew
rs!SL_No = iNewID

'rs!inst_id = Me.Combo27
'rs!EIIN_No = Me.Combo29
rs!Class = Me.Combo31
rs!Category = Me.Combo33
' Me.List49.SetFocus
'rs!loc_code = Me.List49.Text
Me.List47.SetFocus
rs!CurrentSchoolName = Me.List47.Text
rs!S_mobile = Me.Text72
rs!TotSchDay = Me.Text75
rs!T_marks = Me.Text77
rs!StudentID = Me.Combo66
Me.lststuname.SetFocus
rs!Stu_Name = Me.lststuname.Text
Me.List59.SetFocus
rs!FathersName = Me.List59.Text
rs!Attend = Me.Text103

rs.Update
rs.Close

Set dbs = Nothing
Set rs = Nothing

strMSG = "Successfully Inserted Student Information into Database" & Space(5)
MsgBox strMSG, vbInformation, "Save Record"

Call Div_AfterUpdate
Call District_AfterUpdate
Call Upazila_AfterUpdate
End Sub


Private Sub Edit_Button()
Dim dbs As Database, rs As Recordset, iNewID As Integer

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("SELECT * FROM Form1")
rs.Edit

'rs!inst_id = Me.Combo27
'rs!EIIN_No = Me.Combo29
rs!Class = Me.Combo31
rs!Category = Me.Combo33
' Me.List49.SetFocus
'rs!loc_code = Me.List49.Text
Me.List47.SetFocus
rs!CurrentSchoolName = Me.List47.Text
rs!S_mobile = Me.Text72
rs!TotSchDay = Me.Text75
rs!T_marks = Me.Text77
rs!StudentID = Me.Combo66
Me.lststuname.SetFocus
rs!Stu_Name = Me.lststuname.Text
Me.List59.SetFocus
rs!FathersName = Me.List59.Text
rs!Attend = Me.Text103

rs.Update
rs.Close

Set dbs = Nothing
Set rs = Nothing

strMSG = "Successfully Edit Student Information into Database" & Space(5)
MsgBox strMSG, vbInformation, "Save Record"

Call Div_AfterUpdate
Call District_AfterUpdate
Call Upazila_AfterUpdate
End Sub
 
I assume that inst_id is the unique key field on the table and that is causing you a problem so I would have a look at what is being returned in the code below.

Code:
iNewID = Nz(DMax("[SL_No]", "Form1"), 0) + 1
 

Users who are viewing this thread

Back
Top Bottom