Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Problem with If statement and combo box value

Discussion in 'Information Technology' started by Jones Barton, Jul 28, 2006.

  1. Jones Barton

    Jones Barton
    Expand Collapse
    Guest

    Hi Everybody,

    I am trying to write a bit a code that will pop up a msgbox if no selection
    is made in the combo box. It does not appear to be recognizing that the
    value of the combo box is null. Validation will not work as this is in a
    case statement that decides which report to produce based on a selection in
    another combo box. Here is what I have written so far.

    Dim stDocName As String
    Dim stDocName2 As String
    Dim msg

    msg = "For this type of report you must fill in the prior period date
    box."
    stDocName = "Macro_RunSQL_CreateAARReport"
    stDocName2 = "Macro_RunSQL_CreateAARReport_C+P"

    If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then
    MsgBox (msg)
    Exit Sub
    Else
    DoCmd.RunMacro stDocName2
    DoCmd.OpenReport "AAR_Type4", acViewPreview 'Thompsnon
    End If

    Any clues to what I have done wrong?


    Jones
     
  2. Loading...

    Similar Threads Forum Date
    Sikh News Sikhs Face Problems While Carrying Kirpans In Khyber-Pakhtunkhwa - SikhSiyasat.Net Breaking News Jul 29, 2016
    "Dasam" Granth - A Look At The Core Problems Dasam Granth Oct 21, 2015
    Problems In Life Sikh Sikhi Sikhism Apr 13, 2015
    How can I make decent and useful friends and from where ?? most people have a problem with me Sikh Youth Oct 23, 2013
    The Problem with Taking Too Many Vitamins Health & Nutrition Oct 18, 2013

  3. Michael H

    Michael H
    Expand Collapse
    Guest

    Hi.

    Change this:
    If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then

    To this:
    If IsNull(Forms![Create_AAR_Report]![ComboPriorPeriod_Date]) Then

    Think of "Null" as "Unknown". You can't make a comparison to an unknown
    (your If statement), but you can test to find out whether something is
    unknown (my If statement).

    Of course, it is also possible that the control you are testing is not Null,
    but rather an empty string, in which case you'd want to test for that as
    well. For more info on this kind of issue, see:
    http://allenbrowne.com/casu-11.html
    http://allenbrowne.com/casu-12.html

    -Michael



    "Jones Barton" wrote:

    > Hi Everybody,
    >
    > I am trying to write a bit a code that will pop up a msgbox if no selection
    > is made in the combo box. It does not appear to be recognizing that the
    > value of the combo box is null. Validation will not work as this is in a
    > case statement that decides which report to produce based on a selection in
    > another combo box. Here is what I have written so far.
    >
    > Dim stDocName As String
    > Dim stDocName2 As String
    > Dim msg
    >
    > msg = "For this type of report you must fill in the prior period date
    > box."
    > stDocName = "Macro_RunSQL_CreateAARReport"
    > stDocName2 = "Macro_RunSQL_CreateAARReport_C+P"
    >
    > If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then
    > MsgBox (msg)
    > Exit Sub
    > Else
    > DoCmd.RunMacro stDocName2
    > DoCmd.OpenReport "AAR_Type4", acViewPreview 'Thompsnon
    > End If
    >
    > Any clues to what I have done wrong?
    >
    >
    > Jones
    >
     
  4. Jones Barton

    Jones Barton
    Expand Collapse
    Guest

    Michael,

    Spot on with that response, thanks for the help

    "Michael H" wrote:

    > Hi.
    >
    > Change this:
    > If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then
    >
    > To this:
    > If IsNull(Forms![Create_AAR_Report]![ComboPriorPeriod_Date]) Then
    >
    > Think of "Null" as "Unknown". You can't make a comparison to an unknown
    > (your If statement), but you can test to find out whether something is
    > unknown (my If statement).
    >
    > Of course, it is also possible that the control you are testing is not Null,
    > but rather an empty string, in which case you'd want to test for that as
    > well. For more info on this kind of issue, see:
    > http://allenbrowne.com/casu-11.html
    > http://allenbrowne.com/casu-12.html
    >
    > -Michael
    >
    >
    >
    > "Jones Barton" wrote:
    >
    > > Hi Everybody,
    > >
    > > I am trying to write a bit a code that will pop up a msgbox if no selection
    > > is made in the combo box. It does not appear to be recognizing that the
    > > value of the combo box is null. Validation will not work as this is in a
    > > case statement that decides which report to produce based on a selection in
    > > another combo box. Here is what I have written so far.
    > >
    > > Dim stDocName As String
    > > Dim stDocName2 As String
    > > Dim msg
    > >
    > > msg = "For this type of report you must fill in the prior period date
    > > box."
    > > stDocName = "Macro_RunSQL_CreateAARReport"
    > > stDocName2 = "Macro_RunSQL_CreateAARReport_C+P"
    > >
    > > If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then
    > > MsgBox (msg)
    > > Exit Sub
    > > Else
    > > DoCmd.RunMacro stDocName2
    > > DoCmd.OpenReport "AAR_Type4", acViewPreview 'Thompsnon
    > > End If
    > >
    > > Any clues to what I have done wrong?
    > >
    > >
    > > Jones
    > >
     

Share This Page