Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Exit back to a form if a selection is not made

Posted on 2014-10-10
2
Medium Priority
?
94 Views
Last Modified: 2014-10-22
I want to write an If clause that will exit back to a Form if a condition is met.

Here is what I have:

If [Forms]![frm_Date_Selection]![Frame166].Value = 5 Then
    MsgBox "Please Select Report to Run."
    End Sub
End If
If [Forms]![frm_Date_Selection]![Frame137].Value = 13 Then
    MsgBox "Please Select From Month."
    End Sub
End If
If [Forms]![frm_Date_Selection]![List120].Value Is Null Then
    MsgBox "Please Select From Date."
    End Sub
End If

Open in new window


Can you help me out?

Thanks

Glen
0
Comment
Question by:GPSPOW
2 Comments
 
LVL 31

Accepted Solution

by:
Helen Feddema earned 2000 total points
ID: 40396858
First, give the frame a meaningful name, to make your code more comprehensible.  Next, set up a Select Case statement to deal with the possible values.  For exiting to a form, do you mean to cancel another action and return to the calling form, or opening another form?

Here is some sample code for dealing with choices in an option group:

Private Sub cmdMultipleContactsQuery_Click()
'Created by Helen Feddema 28-May-2014
'Last modified by Helen Feddema 30-May-2014

On Error GoTo ErrorHandler
   
   intMethod = Nz(Me![fraMethodQuery].Value, 1)
   
   Select Case intMethod
   
      Case 1
         DoCmd.OpenForm FormName:="frmDocPropsQuery"
         
      Case 3
         DoCmd.OpenForm FormName:="frmTypeTextQuery"
      
      Case 2
         DoCmd.OpenForm FormName:="frmMailMergeQuery"
      
      Case 4
         DoCmd.OpenForm FormName:="frmBookmarksQuery"
         
      Case 5
         DoCmd.OpenForm FormName:="frmCatalogMergeQuery"
         
      Case 6
         DoCmd.OpenForm FormName:="frmFormFieldsQuery"
            
      Case 7
         DoCmd.OpenForm FormName:="frmDocVarsQuery"
            
   End Select
   
   Parent.Visible = False
   
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number _
      & " in " & Me.ActiveControl.Name & " procedure; " _
      & "Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window

0
 

Author Closing Comment

by:GPSPOW
ID: 40397112
Thank you

It worked for me.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question