Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / January 2008

Tip: Looking for answers? Try searching our database.

Keep Focus

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan @BCBS - 31 Jan 2008 17:16 GMT
The code below alerts the user that some fields are blank.
It works until the last line!!!

How can I make it keep the form open an go to the first blank field, then
the second etc..(I'll be adding more)???

Private Sub Form_Close()

If (IsNull(Me.FirstName)) Or (IsNull(Me.LastName)) Then
      If MsgBox("Do you want to Edit Member Information now?", vbQuestion &
vbYesNo, "Question") = vbYes Then
      (Me.???) ???.SetFocus
fredg - 31 Jan 2008 17:31 GMT
> The code below alerts the user that some fields are blank.
> It works until the last line!!!
[quoted text clipped - 8 lines]
> vbYesNo, "Question") = vbYes Then
>        (Me.???) ???.SetFocus

The Close event is too late in the Form closing series of events.
Use the Form's Unload event. You can Cancel the unloading and set
focus where ever you wish.

Private Sub Form_Unload(Cancel as Integer)
If IsNull(Me.FirstName) Or IsNull(Me.LastName) Then
       If MsgBox("Do you want to Edit Member Information now?",
vbQuestion & vbYesNo, "Question") = vbYes Then
        Cancel = True
            Me.[FirstName].SetFocus
       End If
End If
End Sub

Signature

Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

Klatuu - 31 Jan 2008 17:44 GMT
First, you need to move the code to the Form UnLoad event.  The close event
is too late and can't be canceled.  The form will just close.

Private Sub Form_UnLoad(Cancel As Integer)
Dim strCtl As String
Dim blnCancel As Boolean

   If IsNull(Me.FirstName) Then
       blnCancel = True
       strCtl = "FirstName"
   End If

   If IsNull(Me.LastName) Then
       blnCancel = True
       strCtl = "LastName"
   End If    

   If blnCancel Then
       If MsgBox("Do you want to Edit Member Information now?", vbQuestion &
vbYesNo, "Question") = vbYes Then
           Me.Controls(strCtl).SetFocus
           Cancel = True
       End If
   End If
End Sub
Signature

Dave Hargis, Microsoft Access MVP

> The code below alerts the user that some fields are blank.
> It works until the last line!!!
[quoted text clipped - 8 lines]
> vbYesNo, "Question") = vbYes Then
>        (Me.???) ???.SetFocus
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.