I have a form for updating contact details of customers/suppliers. Upon clicking an edit button the user can update txt boxes (as opposed to updating the table data directly and making a mistake). When they press save the below code runs:
Upon closing the form I get a write conflict message, giving me options to save record, copy to clipboard or discard changes. This occurs on different forms as well but this is the example I was able to replicate consistently!
There may be other forms open at the time which may reference the PeopleDetails information, would this have an effect?
If needed the close button code is:
Thanks for any suggestions!
Code:
If Not IsNull(Me.txtp_fname.Value) Then
Dim strFirstName As String
strFirstName = Me.txtp_fname
Dim FirstName As String
FirstName = Replace(strFirstName, "'", "''")
End If
If Not IsNull(Me.txtp_lname.Value) Then
Dim strLastName As String
strLastName = Me.txtp_lname
Dim LastName As String
LastName = Replace(strLastName, "'", "''")
End If
If Not IsNull(Me.txtp_comments.Value) Then
Dim strComments As String
strComments = Me.txtp_comments
Dim Comments As String
Comments = Replace(strComments, "'", "''")
End If
If Not IsNull(Me.txtp_add1.Value) Then
Dim stradd1 As String
stradd1 = Me.txtp_add1
Dim add1 As String
add1 = Replace(stradd1, "'", "''")
End If
If Not IsNull(Me.txtp_add2.Value) Then
Dim stradd2 As String
stradd2 = Me.txtp_add2
Dim add2 As String
add2 = Replace(stradd2, "'", "''")
End If
If Not IsNull(Me.txtp_add3.Value) Then
Dim stradd3 As String
stradd3 = Me.txtp_add3
Dim add3 As String
add3 = Replace(stradd3, "'", "''")
End If
If Not IsNull(Me.txtp_add4.Value) Then
Dim stradd4 As String
stradd4 = Me.txtp_add4
Dim add4 As String
add4 = Replace(stradd4, "'", "''")
End If
If Not IsNull(Me.txtp_county.Value) Then
Dim strcounty As String
strcounty = Me.txtp_county
Dim county As String
county = Replace(strcounty, "'", "''")
End If
If Me.txtRemain < 0 Then
MsgBox "'Comments too long, please update'", vbInformation, "Field length"
Else
DoCmd.SetWarnings False
Dim LResponse As Integer
LResponse = MsgBox("'Update details for '" & Me.txtp_full_name & "' ?'", vbYesNo, "Update details")
If LResponse = vbYes Then
DoCmd.RunSQL "UPDATE tblPeople" & _
" SET p_active=" & Me.chkActive & _
", p_fname='" & FirstName & "'" & _
", p_lname='" & LastName & "'" & _
", p_role='" & Me.txtp_role & "'" & _
", p_tel='" & Me.txtp_tel & "'" & _
", p_mob='" & Me.txtp_mob & "'" & _
", p_email='" & Me.txtp_email & "'" & _
", p_comments='" & Comments & "'" & _
", p_add1='" & add1 & "'" & _
", p_add2='" & add2 & "'" & _
", p_add3='" & add3 & "'" & _
", p_add4='" & add4 & "'" & _
", p_county='" & county & "'" & _
", p_postcode='" & Me.txtp_postcode & "'" & _
", p_send_letter='" & Me.chkp_send_letter & "'" & _
" WHERE p_id=" & Me.p_id
MsgBox "'Person details updated'", vbInformation, "Complete"
Me.txtp_full_name = Me.p_full_name
Me.AllowEdits = False
Me.btnCancel.Enabled = False
Me.btnSave.Enabled = False
Me.btnEdit.Enabled = True
Me.btnClose.Enabled = True
Else
MsgBox "'Details not updated'", vbInformation, "No update"
Me.txtp_fname.Value = Me.p_fname
Me.txtp_lname.Value = Me.p_lname
Me.txtp_role.Value = Me.p_role
Me.txtp_tel.Value = Me.p_tel
Me.txtp_mob.Value = Me.p_mob
Me.txtp_email.Value = Me.p_email
Me.txtp_comments.Value = Me.p_comments
Me.txtp_add1.Value = Me.p_add1
Me.txtp_add2.Value = Me.p_add2
Me.txtp_add3.Value = Me.p_add3
Me.txtp_add4.Value = Me.p_add4
Me.txtp_county.Value = Me.p_county
Me.txtp_postcode.Value = Me.p_postcode
Me.chkActive.Value = Me.p_active
End If
End If
DoCmd.SetWarnings True
End Sub
Upon closing the form I get a write conflict message, giving me options to save record, copy to clipboard or discard changes. This occurs on different forms as well but this is the example I was able to replicate consistently!
There may be other forms open at the time which may reference the PeopleDetails information, would this have an effect?
If needed the close button code is:
Code:
If CurrentProject.AllForms("frmMaster").IsLoaded = True Then
Forms.frmMaster.Requery
DoCmd.Close acForm, "frmPeopleDetails", acSaveNo
ElseIf CurrentProject.AllForms("frmCompanyDetails").IsLoaded = True Then
Forms.frmCompanyDetails.Requery
DoCmd.Close acForm, "frmPeopleDetails", acSaveNo
Else
DoCmd.OpenForm "frmMaster"
DoCmd.Close acForm, "frmPeopleDetails", acSaveNo
End If
Thanks for any suggestions!