JackBurton07
IS-IT--Management
Hi
When I create a new record, my app is overwriting existing records.
Its supposed to create a new id_no ( they are autonumbers in the access database) and update.
However its selecting an existing record and overwriting existing records in the database and at the same time creating a new blank record in the databse.
please help
Public Function CreateNewRecord()
Dim myRS As New ADODB.Recordset()
'open the recordset and have it contain all records in the database table called client'
myRS.Open("client", myDb, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
'add an empty record'
myRS.AddNew()
'update the recordset to include the new entry'
myRS.Update()
myRS.Requery()
'go to the record we just created'
myRS.MoveLast()
'Grab the records ID value so that we can edit it, return this from the function
CreateNewRecord = myRS.Fields("id_no").Value
'Close the record set'
myRS.Close()
End Function
Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
'clear the exisitng fields'
ClearFields()
currentID = CreateNewRecord()
enableall()
cmdUpdate.Enabled = False
txtdaysrem.Enabled = False
txtrate.Enabled = False
txtmat1.Enabled = False
txtterm1.Enabled = False
'get the id_no from creating the new record'
cboclient.Enabled = False
MsgBox("Once you have entered the data into the form click on the update button to save the data to the database", MsgBoxStyle.Information, "Add new record")
End Sub
When I create a new record, my app is overwriting existing records.
Its supposed to create a new id_no ( they are autonumbers in the access database) and update.
However its selecting an existing record and overwriting existing records in the database and at the same time creating a new blank record in the databse.
please help
Public Function CreateNewRecord()
Dim myRS As New ADODB.Recordset()
'open the recordset and have it contain all records in the database table called client'
myRS.Open("client", myDb, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
'add an empty record'
myRS.AddNew()
'update the recordset to include the new entry'
myRS.Update()
myRS.Requery()
'go to the record we just created'
myRS.MoveLast()
'Grab the records ID value so that we can edit it, return this from the function
CreateNewRecord = myRS.Fields("id_no").Value
'Close the record set'
myRS.Close()
End Function
Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
'clear the exisitng fields'
ClearFields()
currentID = CreateNewRecord()
enableall()
cmdUpdate.Enabled = False
txtdaysrem.Enabled = False
txtrate.Enabled = False
txtmat1.Enabled = False
txtterm1.Enabled = False
'get the id_no from creating the new record'
cboclient.Enabled = False
MsgBox("Once you have entered the data into the form click on the update button to save the data to the database", MsgBoxStyle.Information, "Add new record")
End Sub