The following procedure for my button closes the present form and opens another if no data is in [Payee ID] or, if it's not blank, opens a message box with 'Yes' to close this/open other form and 'No' to go back to the [Payee ID] control:
This all works fine, but I'm sure it can be clipped down. I'm sure I shouldn't have to repeat the 'close/open' part. I'm planning to use similar elsewhere, but I can't seem to get to grips with the correct structure of these types of statements. I'd greatly appreciate a pointer to improve matters.
Thank you,
Ted.
Code:
Private Sub Label79_Click()
Dim stDocName As String
stDocName = "SpecialForms"
If IsNull(Me.[Payee ID]) Or Me.[Payee ID] = "" Then
Application.Echo False
DoCmd.Close
DoCmd.OpenForm stDocName
Application.Echo True
Exit Sub
ElseIf MsgBox("Do you wish to close the form and lose entered data?", vbYesNo, "Field(s) contain data!") = vbNo Then
Me.Payee_ID.SetFocus
Else
Application.Echo False
DoCmd.Close
DoCmd.OpenForm stDocName
Application.Echo True
End If
End Sub
Thank you,
Ted.