Solved

How give user an opportunity to exit a form

Posted on 2013-10-25
1
436 Views
Last Modified: 2013-10-25
I have a form with one required field (in the table setup).  And I have the following code in the onclose event of the form.  But I want to give the user the opportunity to exit the form with no data entry if they want to do so.  Here is my code so far:

Private Sub Form_Close()

    If Nz(Me.txtCompanyName, "") = "" Then
        MsgBox "You must enter a company name!!!"
    Exit Sub
    End If

End Sub

How can I present them with a message box that will either let them stay in the form but return the focus to the txtCompanyName field, OR, let them leave the form with no data entry?
0
Comment
Question by:SteveL13
1 Comment
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39601632
try using the unload event of the form instead of the close event

Private Sub Form_Unload(Cancel As Integer)
    If Nz(Me.txtCompanyName, "") = "" Then
        If (MsgBox("You must enter a company name!!!" & vbCrLf & "Do you want to continue?", vbYesNo)) = vbYes Then
               Cancel = True
               Me.txtCompanyName.SetFocus
         Else
               Exit Sub
          End If
    End If
End Sub
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

803 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