Hi experts, I have an update form, even without changes made in fields the form will still be updated. How can I code that the form will not update without changes made. Pls help me. Thanks alot.

below is my code.

Private Sub cmdUpdate_Click()

If Trim(txtLastname.Text) = "" Or Trim(txtFirstname.Text) = "" Or Trim(txtMiddle_Initial.Text) = "" Or Trim(txtAddress.Text) = "" Or Trim(txtContact_No.Text) = "" Or Trim(txtTin_No.Text) = "" Or Trim(txtSSS_No.Text) = "" Or Trim(txtPhilhealth_No.Text) = "" Or Trim(txtPagibig_No.Text) = "" Or (Option1.Value = False And Option2.Value = False) Then
MsgBox "One or more fields is empty.", vbInformation, "Employees"
Exit Sub
End If

Set rs = New ADODB.Recordset
rs.Open "select*from Employees where Employees_IdNo='" + Trim(txtID.Text) + "'", cn, adOpenKeyset, adLockPessimistic

rs!Employees_IdNo = txtID.Text
rs!Lastname = txtLastname.Text
rs!Firstname = txtFirstname.Text
rs!Middle_Initial = txtMiddle_Initial.Text
rs!Address = txtAddress.Text
rs!Gender = cboGender.Text
rs!Birthdate = DTPickerBirthdate
rs!Date_Hired = DTPickerDateHired
rs!Rate = lblRate.Caption
rs!Civil_Status = cboCivil_Status.Text
rs!SSS_No = txtSSS_No.Text
rs!Philhealth_No = txtPhilhealth_No.Text
rs!Pagibig_No = txtPagibig_No.Text
rs!Tin_No = txtTin_No.Text
rs!Contact_No = txtContact_No.Text
rs!Remarks = txtRemarks.Text

If Option1.Value = True Then
Option1.Caption = "Female"
rs!Gender = "Female"

ElseIf Option2.Value = True Then
Option2.Caption = "Male"
rs!Gender = "Male"
End If

Set rs = Nothing
MsgBox "Updated!", vbInformation, "Employee"
End Sub

Edited by kimangel

5 Years
Discussion Span
Last Post by kimangel

do you mean that when user fill up the textbox and if this is same with earlier saved item in database table , then update operation should not take place otherwise update record ?
if this is the issue then use following code

rs.Open "select*from Employees where Employees_IdNo='" & Trim(txtID.Text) & "'", cn, adOpenKeyset, adLockPessimistic
If rs!Lastname = txtLastname.Text Then
MsgBox "Cannot Update !"
Set rs = Nothing
Exit Sub
rs!Lastname = txtLastname.Text
End If

now you can adjust with above code
hope this helps you . . .

Edited by rishif2


It will update every time you click on your cmdUpdate button because you are telling the form to update. Add a cmdCancel button to your form. If the user do not want to update, they can click on cancel and then exit the form...


''Write some code to clear all text boxes...

''Unload form
Unload Me
End Sub

Edited by AndreRet


thank you experts, ill try to code this one. expect a resolved mark as soon as i am done. thanks a lot to both of you.

Votes + Comments
Only a pleasure
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.