Misc Screen Shots.docOnClick Event on Save & Exit Button on form frmFormerEmployerEntry:
Code:
Private Sub btnSaveAndExit_Click()
'Make an entry into the Former Employers Table and exit the form
DoCmd.RunSQL "insert into [tblFormerEmployers] ([numApplID],[txtEmployerName],[txtFmrEmployerPhone],[dteDateFrom],[dteDateTo],[curSalary],[txtSalaryUnit],[txtPosition],[txtLeavingReason]) values(" & numApplicantID & ", txtFldEmployerName,txtFldFmrEmplPhone, dteFldStartDate, dteFldEndDate, curFldOldSalary, cboPayUnits, txtFldPosition,txtFldReasonForLeaving);"
With Me
.txtFldEmployerName = ""
.txtFldAddreess1 = ""
.txtFldAddreess2 = ""
.txtFldCity = ""
.txtFldState = ""
.txtFldZipCode = ""
.txtFldCountry = ""
.txtFldPostalCode = ""
.txtFldFmrEmplPhone = ""
.dteFldStartDate = ""
.dteFldEndDate = ""
.curFldOldSalary = 0
.txtFldPosition = ""
.txtFldReasonForLeaving = ""
End With
DoCmd.Close acForm, "frmFormerEmployerEntry"
Forms![frmEmploymentApp].Requery
End Sub
This works perfectly. However, I have more than one Sub that uses all but the last two lines so I want to reuse that code instead of maintaining two copies.
In a Global module "Reused Code":
Code:
Sub AppendEmployer(frm As Form)
'Make an entry into the Former Employers Table
DoCmd.RunSQL "insert into [tblFormerEmployers] ([numApplID],[txtEmployerName],[txtFmrEmployerPhone],[dteDateFrom],[dteDateTo],[curSalary],[txtSalaryUnit],[txtPosition],[txtLeavingReason]) values(" & numApplicantID & ", frm.txtFldEmployerName, frm.txtFldFmrEmplPhone, frm.dteFldStartDate, frm.dteFldEndDate, frm.curFldOldSalary, frm.cboPayUnits, frm.txtFldPosition,frm.txtFldReasonForLeaving);"
With frm
.txtFldEmployerName = ""
.txtFldAddreess1 = ""
.txtFldAddreess2 = ""
.txtFldCity = ""
.txtFldState = ""
.txtFldZipCode = ""
.txtFldCountry = ""
.txtFldPostalCode = ""
.txtFldFmrEmplPhone = ""
.dteFldStartDate = ""
.dteFldEndDate = ""
.curFldOldSalary = 0
.txtFldPosition = ""
.txtFldReasonForLeaving = ""
End With
End Sub
Changed Original Sub to:
Code:
Private Sub btnSaveAndExit_Click()
Call AppendEmployer(Me)
DoCmd.Close acForm, "frmFormerEmployerEntry"
Forms![frmEmploymentApp].Requery
End Sub
It crashes at DoCmd.RunSQL "insert into [tblFormerEmployers] ([numApplID],[txtEmployerName],[txtFmrEmployerPhone],[dteDateFrom],[dteDateTo],[curSalary],[txtSalaryUnit],[txtPosition],[txtLeavingReason]) values(" & numApplicantID & ", frm.txtFldEmployerName, frm.txtFldFmrEmplPhone, frm.dteFldStartDate, frm.dteFldEndDate, frm.curFldOldSalary, frm.cboPayUnits, frm.txtFldPosition,frm.txtFldReasonForLeaving);"
Not knowing what frm.txtFldEmployerName is, even though my Add Watch shows it ("El Pollo Loco") as plain as day. See attachment.
