Code:
Option Compare Database
Private Sub cmdCancel_Click()
DoCmd.Close acForm, Me.Name, acSaveNo
DoCmd.OpenForm modPubVar.formPrev
End Sub
Private Sub cmdDelete_Click()
If MsgBox("Are you sure you wish to delete this contact? NON REVERSABLE", vbYesNo, "Confirm") = vbNo Then Exit Sub
Dim db As DAO.Database
Dim rcd As DAO.Recordset
Set db = CurrentDb()
Set rcd = db.OpenRecordset("Contacts", dbOpenDynaset)
rcd.MoveLast
rcd.MoveFirst
rcd.FindFirst ("SchoolClub = '" & modPubVar.schoolName & "'")
If MsgBox("Last chance to not delete the contact. Delete?", vbYesNo, "Final Confirmation") = vbNo Then Exit Sub
rcd.Delete
rcd.Update
rcd.Close
MsgBox "Contact deleted"
End Sub
Private Sub cmdPrint_Click()
Dim strSQL As String
strSQL = "SELECT Contacts.ID, Contacts.SchoolClub, Contacts.Address1, Contacts.Address2, Contacts.Address3, Contacts.Address4, Contacts.Postcode, Contacts.Status, Contacts.CoOrdinator, Contacts.Add1, Contacts.add2, Contacts.add3, Contacts.add4, Contacts.postcode2, Contacts.hometel, Contacts.schooltel, Contacts.mobile, Contacts.email, Contacts.notes FROM Contacts WHERE (((Contacts.ID) Like " & [modPubVar].[ContactID] & "));"
If (modPubFunc.setSQLQuery("qryContacts", strSQL)) Then
MsgBox "Failed"
Exit Sub
End If
DoCmd.OpenReport ("Contacts")
strSQL = "SELECT Contacts.ID, Contacts.SchoolClub, Contacts.Address1, Contacts.Address2, Contacts.Address3, Contacts.Address4, Contacts.Postcode, Contacts.Status, Contacts.CoOrdinator, Contacts.Add1, Contacts.add2, Contacts.add3, Contacts.add4, Contacts.postcode2, Contacts.hometel, Contacts.schooltel, Contacts.mobile, Contacts.email, Contacts.notes FROM Contacts WHERE (((Contacts.ID) Like '*'));"
If (modPubFunc.setSQLQuery("qryContacts", strSQL)) Then
MsgBox "Failed"
Exit Sub
End If
End Sub
Private Sub cmdSave_Click()
If MsgBox("Are you sure you wish to save changes?", vbYesNo, "Confirm") = vbNo Then Exit Sub
Dim db As DAO.Database
Dim rcd As DAO.Recordset
Set db = CurrentDb()
Set rcd = db.OpenRecordset("Contacts", dbOpenDynaset)
rcd.MoveLast
rcd.MoveFirst
rcd.FindFirst ("SchoolClub = '" & modPubVar.schoolName & "'")
rcd!SchoolClub = txtSchoolClub
rcd![Address1] = txtAddress1
rcd![Address2] = txtAddress2
rcd![Address3] = txtAddress3
rcd![Address4] = txtAddress4
rcd![Postcode] = txtPostCode1
rcd!schooltel = txtSchTel
rcd!CoOrdinator = txtCoOrdinator
rcd![Add1] = txtadd1
rcd![add2] = txtadd2
rcd![add3] = txtadd3
rcd![add4] = txtadd4
rcd!postcode2 = txtPostCode2
rcd![hometel] = txthometel
rcd!mobile = txtMobile
rcd!email = txtEmail
rcd!Notes = txtNotes
rcd.Close
MsgBox "Changes saved"
End Sub
'Private Sub Form_BeforeUpdate(Cancel As Integer)
' Form_Load
'End Sub
Private Sub Form_Load()
Dim db As DAO.Database
Dim rcd As DAO.Recordset
Set db = CurrentDb()
Set rcd = db.OpenRecordset("Contacts", dbOpenDynaset)
rcd.MoveLast
rcd.MoveFirst
If modPubVar.formPrev = "frmEdit" Then
rcd.FindFirst ("SchoolClub Like '" & modPubVar.schoolName & "*'")
If rcd.NoMatch = True Then
If (MsgBox("No contact found, would you like to add one?", vbYesNo, "No contact") = vbYes) Then
modPubVar.formPrev = Me.Name
DoCmd.Close acForm, Me.Name, acSaveNo
DoCmd.OpenForm "frmNewContact"
Exit Sub
Else
DoCmd.Close acForm, Me.Name, acSaveNo
DoCmd.OpenForm modPubVar.formPrev
Exit Sub
End If
End If
End If
If modPubVar.formPrev = "frmListContacts" Then
rcd.FindFirst ("ID = " & modPubVar.ContactID & "")
If rcd.NoMatch = True Then
If (MsgBox("No contact found, would you like to add one?", vbYesNo, "No contact") = vbYes) Then
modPubVar.formPrev = Me.Name
DoCmd.Close acForm, Me.Name, acSaveNo
DoCmd.OpenForm "frmNewContact"
Exit Sub
End If
End If
End If
txtSchoolClub = rcd!SchoolClub
txtAddress1 = rcd![Address1]
txtAddress2 = rcd![Address2]
txtAddress3 = rcd![Address3]
txtAddress4 = rcd![Address4]
txtPostCode1 = rcd![Postcode]
txtSchTel = rcd!schooltel
txtCoOrdinator = rcd!CoOrdinator
txtadd1 = rcd![Add1]
txtadd2 = rcd![add2]
txtadd3 = rcd![add3]
txtadd4 = rcd![add4]
txtPostCode2 = rcd!postcode2
txthometel = rcd![hometel]
txtMobile = rcd!mobile
txtEmail = rcd!email
txtNotes = rcd!Notes
modPubVar.ContactID = rcd![ID]
rcd.Close
End Sub