Rmaster2022
Member
- Local time
- Today, 00:09
- Joined
- Apr 1, 2022
- Messages
- 32
I have a form in which I have a check box to indicate whether a member is a ruling elder. Another field is a combo box with the names of churches. If the ruling elder box is checked, I want the church field to be required. I know very little VBA, so I copied one that I hoped would work:
Private Sub txtAuthorized_BeforeUpdate(Cancel As Integer)
If Len(txtAuthorized & vbNullString) > 0 And Len(txtChurchCombo & vbNullString) = 0 Then
MsgBox "You need to choose a church!"
Cancel = True
txtChurchCombo.SetFocus
End If
End Sub
When I try it, I get the following message: Run-time error 2108: You must save the field before you execute the GoToControl action, the GoToControl method, or the SetFocus method.
What do I need to change?
To complicate matters, I have another before update event for the same form (There are other fields on the form) as follows (this does work!):
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty = True Then
If MsgBox("Do you want to save the changes for this record?", _
vbYesNo + vbQuestion, "Save Changes?") = vbNo Then
Me.Undo
End If
End If
End Sub
How do I code both of these together to work on the same form.
Private Sub txtAuthorized_BeforeUpdate(Cancel As Integer)
If Len(txtAuthorized & vbNullString) > 0 And Len(txtChurchCombo & vbNullString) = 0 Then
MsgBox "You need to choose a church!"
Cancel = True
txtChurchCombo.SetFocus
End If
End Sub
When I try it, I get the following message: Run-time error 2108: You must save the field before you execute the GoToControl action, the GoToControl method, or the SetFocus method.
What do I need to change?
To complicate matters, I have another before update event for the same form (There are other fields on the form) as follows (this does work!):
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty = True Then
If MsgBox("Do you want to save the changes for this record?", _
vbYesNo + vbQuestion, "Save Changes?") = vbNo Then
Me.Undo
End If
End If
End Sub
How do I code both of these together to work on the same form.