Help with an if/then and displaying a message syntax in a form

TAM

Board Regular
Joined
Oct 10, 2008
Messages
114
The first if statement is working as desired, however I would like to add a message popup that if the user has "yes" in the first field and "n/a" in the next field, they need to select a measurement. Can you help me with the syntax, please?

Private Sub Next_yr_Impact_Change()
Dim Message As String
If Forms![frm_exception_updateModal]![Next_yr_Impact] = "No" Then
Forms![frm_exception_updateModal]![Next_Grid].Value = "n/a"
Forms![frm_exception_updateModal]![GDC_Baseline_Adj].Value = 0
Forms![frm_exception_updateModal]![FP_Baseline].Value = 0
ElseIf Forms![frm_exception_updateModal]![Next_yr_Impact] ="yes" and forms![frm_exception_updatemodal]![Next_Grid].value] = "n/a" Then
Message = "Select Measurement"

End If
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Msgbox "Select Measurement"
If there are other possibilities, like the user may not enter yes, but does enter a grid value (or vice versa), or enter or enter "na" the routine will fail. For more message options, check out the message box function.

PS's: Rarely do you need to reference .value for a form control - it is the default property.
Once your message is dismissed, there is nothing to stop the procedure from running to completion, except error causing code such as this [Next_Grid].value] Note my Exit Sub further down.
Here's a way to type less code

Dim frm as Form
Set frm = "Forms![frm_exception_updateModal]"
If frm.[Next_yr_Impact]...
For larger blocks of code in a post (like what you posted) please use code tags, with the customary indent. Makes it much easier to follow.
Code:
Private Sub Next_yr_Impact_Change()
Dim Message As String
Dim frm as Form

Set frm = "Forms![frm_exception_updateModal]"
If frm.[Next_yr_Impact] = "No" Then
  frm.[Next_Grid] = "n/a"
  frm.[GDC_Baseline_Adj]= 0
  frm[FP_Baseline] = 0
ElseIf  frm.[Next_yr_Impact] ="yes" and  frm.[Next_Grid] = "n/a" Then
   msgbox = "Select Measurement"
  Exit Sub
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,788
Messages
6,161,963
Members
451,734
Latest member
Adapt375

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top