I'm glad you worked it outIt's surprising how a night drinking can help occasionally (as it usually does the opposite!!).
One thing I notice is that you have a few bits of repeated code, which could be put into Subs instead. That way you if things change you don't need to change code in several places, and the other code is much easier to read (as there is far less of it!).
For example, in cmdAdd/cmdDelete/etc you have code like this:
and like this:VB Code:
txtFirstName.Text = vbNullString ... ... txtEmployed.Text = vbNullStringVB Code:
txtFirstName.Enabled = True '(or false, but all the same) ... ... txtEmployed.Enabled = True
These can both be replaced (everywhere in your code that uses them) by a call to a subs like these:
(just paste this before cmdend_Click)VB Code:
Private Sub ClearTextBoxes 'Clear the text in all data text boxes txtFirstName.Text = vbNullString txtLastName.Text = vbNullString txtSocialSecurity.Text = vbNullString txtPhone.Text = vbNullString txtStreet.Text = vbNullString txtCity.Text = vbNullString txtState.Text = vbNullString txtZip.Text = vbNullString txtID.Text = vbNullString txtRate.Text = vbNullString txtGender.Text = vbNullString txtDateofBirth.Text = vbNullString txtEmployed.Text = vbNullString End Sub Private Sub EnableTextBoxes (booEnable as Boolean) 'Enable or disable all data text boxes (pass True to enable all, or False to disable all) txtFirstName.Enabled = booEnable txtLastName.Enabled = booEnable txtSocialSecurity.Enabled = booEnable txtPhone.Enabled = booEnable txtStreet.Enabled = booEnable txtCity.Enabled = booEnable txtState.Enabled = booEnable txtZip.Enabled = booEnable txtID.Enabled = booEnable txtRate.Enabled = booEnable txtGender.Enabled = booEnable txtDateofBirth.Enabled = booEnable txtEmployed.Enabled = booEnable End Sub
These can be used in cmdAdd and cmdDelete like this:
..you can also call them from other places in your code that do the same work.VB Code:
Private Sub cmdDelete_Click() errormsg = MsgBox("Are You Sure You Want To Delete This Record", vbYesNo, "Delete Record") If errormsg = vbYes Then rs.Delete Set rs = db.OpenRecordset("EMPDATA", dbOpenTable) list [B] Call ClearTextBoxes Call EnableTextBoxes(False)[/B] txtSearch.Text = vbNullString cmdSave.Enabled = False cmdCancel.Enabled = False cmdadd.Enabled = True Else Exit Sub End If End Sub Private Sub cmdAdd_Click() [B] Call ClearTextBoxes Call EnableTextBoxes(True)[/B] cmdadd.Enabled = False cmdDelete.Enabled = False cmdEdit.Enabled = False cmdSave.Enabled = True cmdCancel.Enabled = True dbadd = True End Sub




It's surprising how a night drinking can help occasionally (as it usually does the opposite!!).
Reply With Quote