Results 1 to 6 of 6
  1. #1
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    193

    Message

    Hello everyone,
    I do have a database in which cotton processing data is entered. It has a Form in which Factories are added with the following Fields:


    ID, Factory Name, Factory Type (Combo Box), Address, City (Combo Box), State (Combo Box), Contact #, Pin Code #, E Mail ID
    It is a single Form.
    What I need is, if the user closes the Form without selecting data either from all the Combo Boxes or any one of the Combo Boxes, a Message should appear and when the Message Box is closed the cursor should go to the particular Combo Box.
    Please inform the VBA code for this.
    Regards
    Alex

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Something like this code in the forms BeforeUpdate event:
    Code:
    If Nz([Factory Type],0) = 0 Then
       Cancel = True
       Msgbox"Select Factory Type"
       Me.[Factory Type].SetFocus
    ElseIf Nz([City],0) = 0 Then
       Cancel = True
       Msgbox"Select a City"
       Me.[City].SetFocus
    ElseIf Nz([State],0) = 0 Then
       Cancel = True
       Msgbox"Select a State"
       Me.[State].SetFocus
    End If
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    put in all your checks into the ISVALIDFORM routine.
    then if all are good, close the form in the UNLOAD event.


    Code:
    Private Sub Form_Unload(Cancel As Integer)
      cancel =not IsValidForm()
    End Sub
    
    
    '------------
    Private Function IsValidForm() As Boolean
    '------------
    Dim vMsg
    Select Case True
       Case IsNull(dtpWeekOf)
          vMsg = "Date field missing"
       Case IsNull(cboUser)
          vMsg = "Teacher name is missing"
       Case IsNull(cboSubj)
          vMsg = "Subject field is missing"
    End Select
    If vMsg <> "" Then MsgBox vMsg, vbCritical, "Required Field"
    IsValidForm = vMsg = ""
    End Function

  4. #4
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    193
    Thanks Bob & Ranman.
    However, not working.

  5. #5
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    193
    Sorry Bob & Ranman, I made a mistake in the controls spelling. Now it works perfectly.

  6. #6
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    always use OPTION EXPLICIT in every module and it will eliminate spelling errors.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 03-17-2016, 05:53 PM
  2. Replies: 2
    Last Post: 01-23-2014, 12:40 PM
  3. Replies: 15
    Last Post: 11-01-2013, 03:24 PM
  4. Replies: 9
    Last Post: 09-26-2012, 12:20 PM
  5. Message box
    By tomneedshelp in forum Forms
    Replies: 1
    Last Post: 03-22-2012, 10:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums