VBA Challenged
VBA Challenged

Reputation: 23

Creating Message Boxes

In Access 2010, I need to have a Message Box pop-up when the user selects specific text (Real Estate) in a combo-box (ProductType).

In short...if the [ProductType] entered by the user is any one of the multiple "Real Estate" options available, then show a Message Box that states "USER MUST COMPLETE RESPA TRACKING" and then direct them to that page (tab) to complete additional text fields.

I've attached the following code to the BEFORE UPDATE function of the combo box. But that only creates the message, it does not direct them to the tab/fields that need to be entered.

Private Sub ProductType2_BeforeUpdate(Cancel As Integer)
Dim strPrompt As String

strPrompt = "The Product Type selected is Real Estate.  The RESPA Tracking tab MUST be completed at time of App Entry and validated during Underwriting."
If Not IsNull(Me.ProductType2.Value) Then
    If Me.ProductType2.Value Like "Real Estate*" Then
        Cancel = (MsgBox(strPrompt, vbOK) = vbNo)
    End If
End If
End Sub

Upvotes: 0

Views: 58

Answers (1)

HansUp
HansUp

Reputation: 97101

It seems you've solved the creating a MsgBox issue, and now your remaining challenge is to "direct them to the tab/fields that need to be entered".

Use the SetFocus method to place focus on a specific page in your tab control, or on a control within that page.

This command button example shifts focus to the first control on a page named Page1 ...

Private Sub cmdPage1_Click()
    Me!Page1.SetFocus
End Sub

But my guess is you will prefer focus on a specific control within the page. My Page1 contains a text box named txtMemo_field. This version places the focus on that text box. Notice the page name is not mentioned in this version; SetFocus is called on the text box directly ...

Private Sub cmdPage1_Click()
    Me!txtMemo_field.SetFocus
End Sub

Upvotes: 2

Related Questions