Hi there. I've created the form "Formularz" but it does not work as i expected. In a form delete button "Usuń" should remove records from query "Kwerenda" only but it is removing items also from my combo boxes named "Miasto", "Ulica". Records in queries "Kwerenda1" and "Kwerenda2" are related with both combo boxes in form and should be read only (can not be deleted). My solutions works as it should if i will open a form, create a record and remove a record using this delete button without closing of a form window. The described problem is when i will open a form, create a record, close a form window, open a form next time and finally delete a saved record using a delete button. Any ideas how to solve that problem? Btw. Sorry for my english, i'm polish xD This is my VBA code:
Option Explicit
Option Compare Database
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error Resume Next
If IsNull(Me.Ulica.Value) Then
MsgBox "Brak ulicy"
Cancel = True
Me.Ulica.Value.SetFocus
End If
If IsNull(Me.Miasto.Value) Then
MsgBox "Brak miasta"
Cancel = True
Me.Miasto.Value.SetFocus
End If
End Sub
Private Sub cmdNew_Click()
Me.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew
End Sub
Private Sub cmdUsunRekord_Click()
On Error GoTo Err_cmdUsunRekord_Click
DoCmd.SetWarnings False
If MsgBox("Confirm deletion of the record?", vbQuestion + vbYesNo + vbDefaultButton2, "Delete?") = vbYes Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
End If
Exit_cmdUsunRekord_Click:
DoCmd.SetWarnings True
Exit Sub
Err_cmdUsunRekord_Click:
MsgBox Err.Description
Resume Exit_cmdUsunRekord_Click
End Sub
Private Sub Form_Delete(Cancel As Integer)
On Error Resume Next
Miasto.Value.Cancel = True
Ulica.Value.Cancel = True
End Sub