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 / March 2007

Tip: Looking for answers? Try searching our database.

Combo Box Validation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JoeA2006 - 15 Mar 2007 22:33 GMT
I am trying to write a simple procedure to be sure a selection has been made
from a combo box. I would like to call the procedure from the click event of
each button on a form.
My code is

Sub ValidatePeriod()
   If IsNull(Combo1) Then
     MsgBox "You must select a Month"
           Combo1.SetFocus
      Else
          If Not IsNull(Combo1) Then
           Exit Sub
           End If
         
  End If
       
End Sub

After I click OK on the message box the code drops through and continues the
event, without allowing the chance to select a choice. This code works fine
if I put in each procedure, which I am trying to avoid doing.
Ofer Cohen - 15 Mar 2007 22:53 GMT
Use this code as a function that returns True Or False

Function ValidatePeriod()
  ValidatePeriod = True
   If IsNull(Me.Combo1) Then
     MsgBox "You must select a Month"
     Combo1.SetFocus
    ValidatePeriod = False
End If
       
End Function

On the OnClick event of each button call the function, if it returns True
continue with the code, else exit without execute

If ValidatePeriod = True Then

   Your code

End If

Signature

Good Luck
BS"D

> I am trying to write a simple procedure to be sure a selection has been made
> from a combo box. I would like to call the procedure from the click event of
[quoted text clipped - 17 lines]
> event, without allowing the chance to select a choice. This code works fine
> if I put in each procedure, which I am trying to avoid doing.
 
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.