Hi All, sorry for the long post.. looking for some advice
I have created an excel database, where the user uses an entry form to enter data, which then is transferred to the "database" sheet.
I then have an edit button, which allows the user to choose a row of the database, in which the data from that row is returned back into the fields on the form for the user to edit. See some code below:
This all works well.
However, i have recently added validations to some fields in the data entry. E.g. a Works Order Number can only be used once so that there is no duplicate entry for this in the database. this is done like so:
These validations then cause a problem when it comes to editing, as when i click my edit button, edit some data then press save, it gives you the "Works Order Number already in use error" as this number is already in the database.
How should i avoid this?
I have created an excel database, where the user uses an entry form to enter data, which then is transferred to the "database" sheet.
I then have an edit button, which allows the user to choose a row of the database, in which the data from that row is returned back into the fields on the form for the user to edit. See some code below:
VBA Code:
Me.txtRowNumber.Value = Application.WorksheetFunction.Match(Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0), _
ThisWorkbook.Sheets("Database").Range("A:A"), 0)
Me.ModelNo.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 1)
Me.PartNo.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 2)
Me.WorksOrderNo.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 3)
Me.SerialNo.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 4)
Me.MaterialNo.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 5)
Me.SerialNumber.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 6)
Me.txtType.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 7)
Me.txtSize.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 8)
Me.txtWKPRESS.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 9)
Me.txtCertDate.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 10)
Me.BatchNo.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 11)
Me.JobNo.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 12)
Me.DateOfManufacture.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 13)
MultiPage1.Value = 0
MsgBox "Please make the required changes and click on 'Save' button to update.", vbOKOnly + vbInformation, "Edit"
This all works well.
However, i have recently added validations to some fields in the data entry. E.g. a Works Order Number can only be used once so that there is no duplicate entry for this in the database. this is done like so:
Code:
If Application.WorksheetFunction.CountIf(sh.Columns("D:D"), frmForm.WorksOrderNo.Value) > 0 Then
MsgBox frmForm.WorksOrderNo.Value & " - This Works Order Number already exists", vbOKOnly, "PLEASE TRY AGAIN!"
Exit Sub
End If
These validations then cause a problem when it comes to editing, as when i click my edit button, edit some data then press save, it gives you the "Works Order Number already in use error" as this number is already in the database.
How should i avoid this?