Welcome to SPN

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

Sign Up Now!

Don't print report if information is missing!

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

  1. JOM

    JOM
    Expand Collapse
    Guest

    I have a form that am entering data in. There is a print button on the form
    that prints a report based on the information entered in the form. The thing
    is that I do not want it to print the report if information required in the
    form is missing
     
  2. Loading...

    Similar Threads Forum Date
    Ashdoc's Movie Review---Don't Breathe Theatre, Movies & Cinema Sep 19, 2016
    One Step Forward, One Step Backward , You Don't End Up Anywhere Hard Talk Aug 6, 2016
    It Seems Like Almost Everybody Out There Hates Me For Something But I Don't Know What It Is Hard Talk Jun 2, 2016
    You don't want to kill me Harry Blogs Oct 17, 2015
    Windows 10-don't Click That Tab! Information Technology Aug 10, 2015

  3. SusanV

    SusanV
    Expand Collapse
    Guest

    Hi JOM,

    In the PrintReport Button's OnClick event:

    Dim a as string
    dim b as integer
    'etc for however many fields you require

    a = Nz(me.fieldA, "")
    b = Nz(Me.fieldB, 0)

    if a = "" OR b = "" then
    MsgBox "Fill in the fields!"
    Exit Sub
    Else
    docmd.openreport "yourreportname"
    End if


    Of course, you have to put your actual control and report names, etc, and
    list all the controls you want to verify
    --
    hth,
    SusanV

    "JOM" <JOM@discussions.microsoft.com> wrote in message
    news:94709C39-11FD-44DA-9A5D-66B16D719C24@microsoft.com...
    >I have a form that am entering data in. There is a print button on the
    >form
    > that prints a report based on the information entered in the form. The
    > thing
    > is that I do not want it to print the report if information required in
    > the
    > form is missing
     
  4. fredg

    fredg
    Expand Collapse
    Guest

    On Wed, 17 May 2006 11:09:01 -0700, JOM wrote:

    > I have a form that am entering data in. There is a print button on the form
    > that prints a report based on the information entered in the form. The thing
    > is that I do not want it to print the report if information required in the
    > form is missing


    Then you need to verify, in the form, that all of your data is present
    before you actually open the report.
    Code the print button click event:

    If IsNull([FieldA] Or IsNull([FieldB] Or IsNull([Etc...])Then
    MsgBox "Missing Data"
    [SomeControl].SetFocus
    Else
    DoCmd.Openreport "ReportName", acViewPreview
    End if

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

    BruceM
    Expand Collapse
    Guest

    The place to trap that sort of thing is at the form. You can use the form's
    Before Update event:

    If IsNull(Me.SomeField) Then
    msgbox
    Me.txtSomeField.SetFocus
    End If

    You may want to provide users with a way to bail out if they didn't mean to
    create the record. Me.Undo, either in a Cancel command button or as part of
    another event, is one way. One possibility:

    If MsgBox("SomeField needs to be filled in", vbOKCancel, "Missing Data)
    = vbCancel Then
    Me.Undo
    DoCmd.GoToRecord , , acPrevious
    Cancel = True
    Else
    Me.txtSomeField.SetFocus
    Cancel = True
    End If

    The last Cancel = True will help if you have a several such tests. If it
    finds one it won't bother to check the others. If you are testing for just
    one field then I don't think it's necessary.

    "JOM" <JOM@discussions.microsoft.com> wrote in message
    news:94709C39-11FD-44DA-9A5D-66B16D719C24@microsoft.com...
    >I have a form that am entering data in. There is a print button on the
    >form
    > that prints a report based on the information entered in the form. The
    > thing
    > is that I do not want it to print the report if information required in
    > the
    > form is missing
     
  6. Michael H

    Michael H
    Expand Collapse
    Guest

    Hi.

    The way I handle this is to place the following in a code module not
    associated with any particular form. You'll probably want to change the text
    of the message so that it directs the user to fill in any missing fields.

    Public Sub NoReportData()
    MsgBox "There is no data to print." _
    & vbCrLf & vbCrLf & "The report has been canceled. " & vbCrLf _
    & vbCrLf & "Check the source of data for the report to make sure you
    " _
    & vbCrLf & "entered the correct criteria (for example, a valid range
    " _
    & vbCrLf & "of dates).", vbOKOnly + vbExclamation, "No Data"
    End Sub

    Then, for each report you have, place the following code in the report's "On
    No Data" event:

    NoReportData
    Cancel = True


    -Michael



    "JOM" wrote:

    > I have a form that am entering data in. There is a print button on the form
    > that prints a report based on the information entered in the form. The thing
    > is that I do not want it to print the report if information required in the
    > form is missing
     
  7. SusanV

    SusanV
    Expand Collapse
    Guest

    Hi Fred,
    Am I wrong about this - If the user entered something then deleted it, then
    the control contains an empty string which won't trigger the 'If IsNull... '
    ???

    SusanV


    "fredg" <fgutkind@example.invalid> wrote in message
    news:1n5itybzi1pe5.1kmhrps1yfchq$.dlg@40tude.net...
    > On Wed, 17 May 2006 11:09:01 -0700, JOM wrote:
    >
    >> I have a form that am entering data in. There is a print button on the
    >> form
    >> that prints a report based on the information entered in the form. The
    >> thing
    >> is that I do not want it to print the report if information required in
    >> the
    >> form is missing

    >
    > Then you need to verify, in the form, that all of your data is present
    > before you actually open the report.
    > Code the print button click event:
    >
    > If IsNull([FieldA] Or IsNull([FieldB] Or IsNull([Etc...])Then
    > MsgBox "Missing Data"
    > [SomeControl].SetFocus
    > Else
    > DoCmd.Openreport "ReportName", acViewPreview
    > End if
    >
    > --
    > Fred
    > Please respond only to this newsgroup.
    > I do not reply to personal e-mail
     
  8. JOM

    JOM
    Expand Collapse
    Guest

    Thanks SusanV, however I have a question, I also have several checkboxes a
    user is required select at one one of the checkboxes, so how will incorporate
    this in the what you sent me.
    Note: the several checkboxes have a tag - ChxGr

    "SusanV" wrote:

    > Hi JOM,
    >
    > In the PrintReport Button's OnClick event:
    >
    > Dim a as string
    > dim b as integer
    > 'etc for however many fields you require
    >
    > a = Nz(me.fieldA, "")
    > b = Nz(Me.fieldB, 0)
    >
    > if a = "" OR b = "" then
    > MsgBox "Fill in the fields!"
    > Exit Sub
    > Else
    > docmd.openreport "yourreportname"
    > End if
    >
    >
    > Of course, you have to put your actual control and report names, etc, and
    > list all the controls you want to verify
    > --
    > hth,
    > SusanV
    >
    > "JOM" <JOM@discussions.microsoft.com> wrote in message
    > news:94709C39-11FD-44DA-9A5D-66B16D719C24@microsoft.com...
    > >I have a form that am entering data in. There is a print button on the
    > >form
    > > that prints a report based on the information entered in the form. The
    > > thing
    > > is that I do not want it to print the report if information required in
    > > the
    > > form is missing

    >
    >
    >
     
  9. BruceM

    BruceM
    Expand Collapse
    Guest

    My tests have shown that an IsNull message will still be generated. If
    there is concern about empty strings then the Len and Nz functions can be
    combined:
    If Len(Nz(Me.SomeField,"")) <= 0 Then
    etc.

    "SusanV" <svanallen@nospam-mvps.org> wrote in message
    news:eqTOQ$deGHA.1320@TK2MSFTNGP04.phx.gbl...
    > Hi Fred,
    > Am I wrong about this - If the user entered something then deleted it,
    > then the control contains an empty string which won't trigger the 'If
    > IsNull... ' ???
    >
    > SusanV
    >
    >
    > "fredg" <fgutkind@example.invalid> wrote in message
    > news:1n5itybzi1pe5.1kmhrps1yfchq$.dlg@40tude.net...
    >> On Wed, 17 May 2006 11:09:01 -0700, JOM wrote:
    >>
    >>> I have a form that am entering data in. There is a print button on the
    >>> form
    >>> that prints a report based on the information entered in the form. The
    >>> thing
    >>> is that I do not want it to print the report if information required in
    >>> the
    >>> form is missing

    >>
    >> Then you need to verify, in the form, that all of your data is present
    >> before you actually open the report.
    >> Code the print button click event:
    >>
    >> If IsNull([FieldA] Or IsNull([FieldB] Or IsNull([Etc...])Then
    >> MsgBox "Missing Data"
    >> [SomeControl].SetFocus
    >> Else
    >> DoCmd.Openreport "ReportName", acViewPreview
    >> End if
    >>
    >> --
    >> Fred
    >> Please respond only to this newsgroup.
    >> I do not reply to personal e-mail

    >
    >
     
  10. SusanV

    SusanV
    Expand Collapse
    Guest

    Hi JOM,

    Checkboxes are Boolean fields, and can be tested as either -1, Yes, or True
    (all of those indicate the box IS checked), so if you wanted to do something
    ONLY if the box is checked (I prefer the -1 to the verbal, you can use
    either):

    If Me.Checkbox <> -1 then
    MsgBox "Box not checked"
    Exit Sub
    Else
    DoCmd.OpenReport "YourReport"
    End If

    To incorporate this into the other verifications, add it as an OR:

    if a = "" OR b = "" OR Me.Checkbox <> -1 Then
    MsgBox "Fill in the fields! Check the Checkbox!"
    Exit Sub
    Else
    DoCmd.OpenReport "YourReportName"
    End if


    If the user needs to check ONE box and ONLY ONE box, then this should be an
    option group rather than individual checkbox controls on the form, but
    that's another subject.

    ;-D

    --
    SusanV


    "JOM" <JOM@discussions.microsoft.com> wrote in message
    news:3A55AB89-42F2-4FF0-8233-1E3B5F6278FB@microsoft.com...
    > Thanks SusanV, however I have a question, I also have several checkboxes a
    > user is required select at one one of the checkboxes, so how will
    > incorporate
    > this in the what you sent me.
    > Note: the several checkboxes have a tag - ChxGr
    >
    > "SusanV" wrote:
    >
    >> Hi JOM,
    >>
    >> In the PrintReport Button's OnClick event:
    >>
    >> Dim a as string
    >> dim b as integer
    >> 'etc for however many fields you require
    >>
    >> a = Nz(me.fieldA, "")
    >> b = Nz(Me.fieldB, 0)
    >>
    >> if a = "" OR b = "" then
    >> MsgBox "Fill in the fields!"
    >> Exit Sub
    >> Else
    >> docmd.openreport "yourreportname"
    >> End if
    >>
    >>
    >> Of course, you have to put your actual control and report names, etc, and
    >> list all the controls you want to verify
    >> --
    >> hth,
    >> SusanV
    >>
    >> "JOM" <JOM@discussions.microsoft.com> wrote in message
    >> news:94709C39-11FD-44DA-9A5D-66B16D719C24@microsoft.com...
    >> >I have a form that am entering data in. There is a print button on the
    >> >form
    >> > that prints a report based on the information entered in the form. The
    >> > thing
    >> > is that I do not want it to print the report if information required in
    >> > the
    >> > form is missing

    >>
    >>
    >>
     
  11. JOM

    JOM
    Expand Collapse
    Guest

    Thanks Bruce, I did post another question as follows:
    I also have several checkboxes a user is required select at one one of the
    checkboxes, so how will incorporate this in the what you sent me.
    Note: the several checkboxes have a tag - ChxGr

    "BruceM" wrote:

    > My tests have shown that an IsNull message will still be generated. If
    > there is concern about empty strings then the Len and Nz functions can be
    > combined:
    > If Len(Nz(Me.SomeField,"")) <= 0 Then
    > etc.
    >
    > "SusanV" <svanallen@nospam-mvps.org> wrote in message
    > news:eqTOQ$deGHA.1320@TK2MSFTNGP04.phx.gbl...
    > > Hi Fred,
    > > Am I wrong about this - If the user entered something then deleted it,
    > > then the control contains an empty string which won't trigger the 'If
    > > IsNull... ' ???
    > >
    > > SusanV
    > >
    > >
    > > "fredg" <fgutkind@example.invalid> wrote in message
    > > news:1n5itybzi1pe5.1kmhrps1yfchq$.dlg@40tude.net...
    > >> On Wed, 17 May 2006 11:09:01 -0700, JOM wrote:
    > >>
    > >>> I have a form that am entering data in. There is a print button on the
    > >>> form
    > >>> that prints a report based on the information entered in the form. The
    > >>> thing
    > >>> is that I do not want it to print the report if information required in
    > >>> the
    > >>> form is missing
    > >>
    > >> Then you need to verify, in the form, that all of your data is present
    > >> before you actually open the report.
    > >> Code the print button click event:
    > >>
    > >> If IsNull([FieldA] Or IsNull([FieldB] Or IsNull([Etc...])Then
    > >> MsgBox "Missing Data"
    > >> [SomeControl].SetFocus
    > >> Else
    > >> DoCmd.Openreport "ReportName", acViewPreview
    > >> End if
    > >>
    > >> --
    > >> Fred
    > >> Please respond only to this newsgroup.
    > >> I do not reply to personal e-mail

    > >
    > >

    >
    >
    >
     
  12. BruceM

    BruceM
    Expand Collapse
    Guest

    Susan's reply covers this question.

    "JOM" <JOM@discussions.microsoft.com> wrote in message
    news:BED96C37-6CC1-473E-A564-4E59AE692C34@microsoft.com...
    > Thanks Bruce, I did post another question as follows:
    > I also have several checkboxes a user is required select at one one of the
    > checkboxes, so how will incorporate this in the what you sent me.
    > Note: the several checkboxes have a tag - ChxGr
    >
    > "BruceM" wrote:
    >
    >> My tests have shown that an IsNull message will still be generated. If
    >> there is concern about empty strings then the Len and Nz functions can be
    >> combined:
    >> If Len(Nz(Me.SomeField,"")) <= 0 Then
    >> etc.
    >>
    >> "SusanV" <svanallen@nospam-mvps.org> wrote in message
    >> news:eqTOQ$deGHA.1320@TK2MSFTNGP04.phx.gbl...
    >> > Hi Fred,
    >> > Am I wrong about this - If the user entered something then deleted it,
    >> > then the control contains an empty string which won't trigger the 'If
    >> > IsNull... ' ???
    >> >
    >> > SusanV
    >> >
    >> >
    >> > "fredg" <fgutkind@example.invalid> wrote in message
    >> > news:1n5itybzi1pe5.1kmhrps1yfchq$.dlg@40tude.net...
    >> >> On Wed, 17 May 2006 11:09:01 -0700, JOM wrote:
    >> >>
    >> >>> I have a form that am entering data in. There is a print button on
    >> >>> the
    >> >>> form
    >> >>> that prints a report based on the information entered in the form.
    >> >>> The
    >> >>> thing
    >> >>> is that I do not want it to print the report if information required
    >> >>> in
    >> >>> the
    >> >>> form is missing
    >> >>
    >> >> Then you need to verify, in the form, that all of your data is present
    >> >> before you actually open the report.
    >> >> Code the print button click event:
    >> >>
    >> >> If IsNull([FieldA] Or IsNull([FieldB] Or IsNull([Etc...])Then
    >> >> MsgBox "Missing Data"
    >> >> [SomeControl].SetFocus
    >> >> Else
    >> >> DoCmd.Openreport "ReportName", acViewPreview
    >> >> End if
    >> >>
    >> >> --
    >> >> Fred
    >> >> Please respond only to this newsgroup.
    >> >> I do not reply to personal e-mail
    >> >
    >> >

    >>
    >>
    >>
     
  13. JOM

    JOM
    Expand Collapse
    Guest

    Thanks for the response.

    I was thinking not to type all that checkboxes I have on my form, there are
    about 15 of them, so I put a tag on them to avoid typing all of them. Is it
    possible to use a tag and not the checkboxes names?

    "SusanV" wrote:

    > Hi JOM,
    >
    > Checkboxes are Boolean fields, and can be tested as either -1, Yes, or True
    > (all of those indicate the box IS checked), so if you wanted to do something
    > ONLY if the box is checked (I prefer the -1 to the verbal, you can use
    > either):
    >
    > If Me.Checkbox <> -1 then
    > MsgBox "Box not checked"
    > Exit Sub
    > Else
    > DoCmd.OpenReport "YourReport"
    > End If
    >
    > To incorporate this into the other verifications, add it as an OR:
    >
    > if a = "" OR b = "" OR Me.Checkbox <> -1 Then
    > MsgBox "Fill in the fields! Check the Checkbox!"
    > Exit Sub
    > Else
    > DoCmd.OpenReport "YourReportName"
    > End if
    >
    >
    > If the user needs to check ONE box and ONLY ONE box, then this should be an
    > option group rather than individual checkbox controls on the form, but
    > that's another subject.
    >
    > ;-D
    >
    > --
    > SusanV
    >
    >
    > "JOM" <JOM@discussions.microsoft.com> wrote in message
    > news:3A55AB89-42F2-4FF0-8233-1E3B5F6278FB@microsoft.com...
    > > Thanks SusanV, however I have a question, I also have several checkboxes a
    > > user is required select at one one of the checkboxes, so how will
    > > incorporate
    > > this in the what you sent me.
    > > Note: the several checkboxes have a tag - ChxGr
    > >
    > > "SusanV" wrote:
    > >
    > >> Hi JOM,
    > >>
    > >> In the PrintReport Button's OnClick event:
    > >>
    > >> Dim a as string
    > >> dim b as integer
    > >> 'etc for however many fields you require
    > >>
    > >> a = Nz(me.fieldA, "")
    > >> b = Nz(Me.fieldB, 0)
    > >>
    > >> if a = "" OR b = "" then
    > >> MsgBox "Fill in the fields!"
    > >> Exit Sub
    > >> Else
    > >> docmd.openreport "yourreportname"
    > >> End if
    > >>
    > >>
    > >> Of course, you have to put your actual control and report names, etc, and
    > >> list all the controls you want to verify
    > >> --
    > >> hth,
    > >> SusanV
    > >>
    > >> "JOM" <JOM@discussions.microsoft.com> wrote in message
    > >> news:94709C39-11FD-44DA-9A5D-66B16D719C24@microsoft.com...
    > >> >I have a form that am entering data in. There is a print button on the
    > >> >form
    > >> > that prints a report based on the information entered in the form. The
    > >> > thing
    > >> > is that I do not want it to print the report if information required in
    > >> > the
    > >> > form is missing
    > >>
    > >>
    > >>

    >
    >
    >
     
  14. JOM

    JOM
    Expand Collapse
    Guest

    Bruce, The idea that Susan gave was good but the question is there are about
    15 checkboxes at least any 1 should be checked. So I put a tag on them to
    avoid typing all of them. Is it possible to use a tag and not the checkboxes
    names and at least one is checked??


    "BruceM" wrote:

    > Susan's reply covers this question.
    >
    > "JOM" <JOM@discussions.microsoft.com> wrote in message
    > news:BED96C37-6CC1-473E-A564-4E59AE692C34@microsoft.com...
    > > Thanks Bruce, I did post another question as follows:
    > > I also have several checkboxes a user is required select at one one of the
    > > checkboxes, so how will incorporate this in the what you sent me.
    > > Note: the several checkboxes have a tag - ChxGr
    > >
    > > "BruceM" wrote:
    > >
    > >> My tests have shown that an IsNull message will still be generated. If
    > >> there is concern about empty strings then the Len and Nz functions can be
    > >> combined:
    > >> If Len(Nz(Me.SomeField,"")) <= 0 Then
    > >> etc.
    > >>
    > >> "SusanV" <svanallen@nospam-mvps.org> wrote in message
    > >> news:eqTOQ$deGHA.1320@TK2MSFTNGP04.phx.gbl...
    > >> > Hi Fred,
    > >> > Am I wrong about this - If the user entered something then deleted it,
    > >> > then the control contains an empty string which won't trigger the 'If
    > >> > IsNull... ' ???
    > >> >
    > >> > SusanV
    > >> >
    > >> >
    > >> > "fredg" <fgutkind@example.invalid> wrote in message
    > >> > news:1n5itybzi1pe5.1kmhrps1yfchq$.dlg@40tude.net...
    > >> >> On Wed, 17 May 2006 11:09:01 -0700, JOM wrote:
    > >> >>
    > >> >>> I have a form that am entering data in. There is a print button on
    > >> >>> the
    > >> >>> form
    > >> >>> that prints a report based on the information entered in the form.
    > >> >>> The
    > >> >>> thing
    > >> >>> is that I do not want it to print the report if information required
    > >> >>> in
    > >> >>> the
    > >> >>> form is missing
    > >> >>
    > >> >> Then you need to verify, in the form, that all of your data is present
    > >> >> before you actually open the report.
    > >> >> Code the print button click event:
    > >> >>
    > >> >> If IsNull([FieldA] Or IsNull([FieldB] Or IsNull([Etc...])Then
    > >> >> MsgBox "Missing Data"
    > >> >> [SomeControl].SetFocus
    > >> >> Else
    > >> >> DoCmd.Openreport "ReportName", acViewPreview
    > >> >> End if
    > >> >>
    > >> >> --
    > >> >> Fred
    > >> >> Please respond only to this newsgroup.
    > >> >> I do not reply to personal e-mail
    > >> >
    > >> >
    > >>
    > >>
    > >>

    >
    >
    >
     
  15. SusanV

    SusanV
    Expand Collapse
    Guest

    I'm not sure what you mean by a "tag" - 15 boxes = 15 controls...???

    "JOM" <JOM@discussions.microsoft.com> wrote in message
    news:DBDDB68F-55B3-4997-BCBC-3698F3CAEFE2@microsoft.com...
    > Thanks for the response.
    >
    > I was thinking not to type all that checkboxes I have on my form, there
    > are
    > about 15 of them, so I put a tag on them to avoid typing all of them. Is
    > it
    > possible to use a tag and not the checkboxes names?
    >
    > "SusanV" wrote:
    >
    >> Hi JOM,
    >>
    >> Checkboxes are Boolean fields, and can be tested as either -1, Yes, or
    >> True
    >> (all of those indicate the box IS checked), so if you wanted to do
    >> something
    >> ONLY if the box is checked (I prefer the -1 to the verbal, you can use
    >> either):
    >>
    >> If Me.Checkbox <> -1 then
    >> MsgBox "Box not checked"
    >> Exit Sub
    >> Else
    >> DoCmd.OpenReport "YourReport"
    >> End If
    >>
    >> To incorporate this into the other verifications, add it as an OR:
    >>
    >> if a = "" OR b = "" OR Me.Checkbox <> -1 Then
    >> MsgBox "Fill in the fields! Check the Checkbox!"
    >> Exit Sub
    >> Else
    >> DoCmd.OpenReport "YourReportName"
    >> End if
    >>
    >>
    >> If the user needs to check ONE box and ONLY ONE box, then this should be
    >> an
    >> option group rather than individual checkbox controls on the form, but
    >> that's another subject.
    >>
    >> ;-D
    >>
    >> --
    >> SusanV
    >>
    >>
    >> "JOM" <JOM@discussions.microsoft.com> wrote in message
    >> news:3A55AB89-42F2-4FF0-8233-1E3B5F6278FB@microsoft.com...
    >> > Thanks SusanV, however I have a question, I also have several
    >> > checkboxes a
    >> > user is required select at one one of the checkboxes, so how will
    >> > incorporate
    >> > this in the what you sent me.
    >> > Note: the several checkboxes have a tag - ChxGr
    >> >
    >> > "SusanV" wrote:
    >> >
    >> >> Hi JOM,
    >> >>
    >> >> In the PrintReport Button's OnClick event:
    >> >>
    >> >> Dim a as string
    >> >> dim b as integer
    >> >> 'etc for however many fields you require
    >> >>
    >> >> a = Nz(me.fieldA, "")
    >> >> b = Nz(Me.fieldB, 0)
    >> >>
    >> >> if a = "" OR b = "" then
    >> >> MsgBox "Fill in the fields!"
    >> >> Exit Sub
    >> >> Else
    >> >> docmd.openreport "yourreportname"
    >> >> End if
    >> >>
    >> >>
    >> >> Of course, you have to put your actual control and report names, etc,
    >> >> and
    >> >> list all the controls you want to verify
    >> >> --
    >> >> hth,
    >> >> SusanV
    >> >>
    >> >> "JOM" <JOM@discussions.microsoft.com> wrote in message
    >> >> news:94709C39-11FD-44DA-9A5D-66B16D719C24@microsoft.com...
    >> >> >I have a form that am entering data in. There is a print button on
    >> >> >the
    >> >> >form
    >> >> > that prints a report based on the information entered in the form.
    >> >> > The
    >> >> > thing
    >> >> > is that I do not want it to print the report if information required
    >> >> > in
    >> >> > the
    >> >> > form is missing
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
     
  16. Peter Hibbs

    Peter Hibbs
    Expand Collapse
    Guest

    JOM

    Just a quick recap, as I understand it you have 15 or more check boxes on a
    form and you want to allow the user to only do something if one or more of
    the boxes are ticked and you (quite rightly) do not want to have 15 or so If
    - Then statements in the code. If that is correct then try pasting the
    following function code into your form module (not the dashes, of course).

    ---------------------------------------------
    Public Function ChecksOK() As Boolean

    'Returns TRUE if ANY check box on current form is ticked, else returns FALSE

    Dim cntl As Control

    For Each cntl In Me.Controls 'cycle thru all controls on
    form
    If cntl.ControlType = acCheckBox Then 'if Control type = CheckBox
    then
    If cntl = True Then ChecksOK = True 'if check box ticked then
    ChecksOK = True
    End If
    Next cntl

    End Function
    ---------------------------------------------

    You can then call the function like this :-

    If ChecksOK = False Then
    'show error message or whatever
    Else
    'print report or exit form or whatever
    End If

    Note that this will check ALL the Check Boxes on the form, if there are any
    that are not included in your checks then you will need to modify the
    function code accordingly. You could also modify the code to include multiple
    Text boxes, Combo boxes, etc. The reference codes for these would be
    acTextBox and acComboBox.

    Please let us know if this solves your problem, it may be helpful to other
    programmers.
    --
    Peter Hibbs
     
  17. SusanV

    SusanV
    Expand Collapse
    Guest

    Nice Peter - thanks for sharing!

    <copies and pastes for future reference>

    ;-)

    SusanV

    "Peter Hibbs" <peter.hibbs@btinternet.com.NO_SPAM> wrote in message
    news:BC3A7152-EC06-4493-A098-8271D52CFBB2@microsoft.com...
    > JOM
    >
    > Just a quick recap, as I understand it you have 15 or more check boxes on
    > a
    > form and you want to allow the user to only do something if one or more of
    > the boxes are ticked and you (quite rightly) do not want to have 15 or so
    > If
    > - Then statements in the code. If that is correct then try pasting the
    > following function code into your form module (not the dashes, of course).
    >
    > ---------------------------------------------
    > Public Function ChecksOK() As Boolean
    >
    > 'Returns TRUE if ANY check box on current form is ticked, else returns
    > FALSE
    >
    > Dim cntl As Control
    >
    > For Each cntl In Me.Controls 'cycle thru all controls on
    > form
    > If cntl.ControlType = acCheckBox Then 'if Control type = CheckBox
    > then
    > If cntl = True Then ChecksOK = True 'if check box ticked then
    > ChecksOK = True
    > End If
    > Next cntl
    >
    > End Function
    > ---------------------------------------------
    >
    > You can then call the function like this :-
    >
    > If ChecksOK = False Then
    > 'show error message or whatever
    > Else
    > 'print report or exit form or whatever
    > End If
    >
    > Note that this will check ALL the Check Boxes on the form, if there are
    > any
    > that are not included in your checks then you will need to modify the
    > function code accordingly. You could also modify the code to include
    > multiple
    > Text boxes, Combo boxes, etc. The reference codes for these would be
    > acTextBox and acComboBox.
    >
    > Please let us know if this solves your problem, it may be helpful to other
    > programmers.
    > --
    > Peter Hibbs
    >
    >
     
  18. BruceM

    BruceM
    Expand Collapse
    Guest

    I came up with something similar, but from a slightly different angle. The
    Tag property of the check boxes you want to test could be set to, say, 2.
    Then you could have something like this in the form's Before Update event:

    Dim ctl As Control
    Dim blnChkBox As Boolean

    blnChkOK = False

    For Each ctl In Me.Controls
    If ctl.Tag = 2 Then
    If ctl.Value = -1 Then
    blnChkBox = True
    End If
    End If
    Next ctl

    If blnChkBox = False Then
    MsgBox "You need to check at least one box"
    Cancel = True
    End If

    In this way other check boxes can be ignored. However, if the only check
    boxes are the ones in question, control type can be used.

    To the person who posted the original question, an option group can be a
    good way of handling this sort of situation.

    "Peter Hibbs" <peter.hibbs@btinternet.com.NO_SPAM> wrote in message
    news:BC3A7152-EC06-4493-A098-8271D52CFBB2@microsoft.com...
    > JOM
    >
    > Just a quick recap, as I understand it you have 15 or more check boxes on
    > a
    > form and you want to allow the user to only do something if one or more of
    > the boxes are ticked and you (quite rightly) do not want to have 15 or so
    > If
    > - Then statements in the code. If that is correct then try pasting the
    > following function code into your form module (not the dashes, of course).
    >
    > ---------------------------------------------
    > Public Function ChecksOK() As Boolean
    >
    > 'Returns TRUE if ANY check box on current form is ticked, else returns
    > FALSE
    >
    > Dim cntl As Control
    >
    > For Each cntl In Me.Controls 'cycle thru all controls on
    > form
    > If cntl.ControlType = acCheckBox Then 'if Control type = CheckBox
    > then
    > If cntl = True Then ChecksOK = True 'if check box ticked then
    > ChecksOK = True
    > End If
    > Next cntl
    >
    > End Function
    > ---------------------------------------------
    >
    > You can then call the function like this :-
    >
    > If ChecksOK = False Then
    > 'show error message or whatever
    > Else
    > 'print report or exit form or whatever
    > End If
    >
    > Note that this will check ALL the Check Boxes on the form, if there are
    > any
    > that are not included in your checks then you will need to modify the
    > function code accordingly. You could also modify the code to include
    > multiple
    > Text boxes, Combo boxes, etc. The reference codes for these would be
    > acTextBox and acComboBox.
    >
    > Please let us know if this solves your problem, it may be helpful to other
    > programmers.
    > --
    > Peter Hibbs
    >
    >
     
  19. SusanV

    SusanV
    Expand Collapse
    Guest

    Hi Bruce,

    Do you have handy any links about the Tag Property for Access VBA? This
    looks quite useful, I'd like to learn more about it - but all I can seem to
    find on MSDN is info on using in DotNet.

    TIA,

    SusanV

    "BruceM" <bamoob@yawwhodawtcalm.not> wrote in message
    news:uwHfkOneGHA.764@TK2MSFTNGP05.phx.gbl...
    >I came up with something similar, but from a slightly different angle. The
    >Tag property of the check boxes you want to test could be set to, say, 2.
    >Then you could have something like this in the form's Before Update event:
    >
    > Dim ctl As Control
    > Dim blnChkBox As Boolean
    >
    > blnChkOK = False
    >
    > For Each ctl In Me.Controls
    > If ctl.Tag = 2 Then
    > If ctl.Value = -1 Then
    > blnChkBox = True
    > End If
    > End If
    > Next ctl
    >
    > If blnChkBox = False Then
    > MsgBox "You need to check at least one box"
    > Cancel = True
    > End If
    >
    > In this way other check boxes can be ignored. However, if the only check
    > boxes are the ones in question, control type can be used.
    >
    > To the person who posted the original question, an option group can be a
    > good way of handling this sort of situation.
    >
    > "Peter Hibbs" <peter.hibbs@btinternet.com.NO_SPAM> wrote in message
    > news:BC3A7152-EC06-4493-A098-8271D52CFBB2@microsoft.com...
    >> JOM
    >>
    >> Just a quick recap, as I understand it you have 15 or more check boxes on
    >> a
    >> form and you want to allow the user to only do something if one or more
    >> of
    >> the boxes are ticked and you (quite rightly) do not want to have 15 or so
    >> If
    >> - Then statements in the code. If that is correct then try pasting the
    >> following function code into your form module (not the dashes, of
    >> course).
    >>
    >> ---------------------------------------------
    >> Public Function ChecksOK() As Boolean
    >>
    >> 'Returns TRUE if ANY check box on current form is ticked, else returns
    >> FALSE
    >>
    >> Dim cntl As Control
    >>
    >> For Each cntl In Me.Controls 'cycle thru all controls
    >> on
    >> form
    >> If cntl.ControlType = acCheckBox Then 'if Control type =
    >> CheckBox
    >> then
    >> If cntl = True Then ChecksOK = True 'if check box ticked then
    >> ChecksOK = True
    >> End If
    >> Next cntl
    >>
    >> End Function
    >> ---------------------------------------------
    >>
    >> You can then call the function like this :-
    >>
    >> If ChecksOK = False Then
    >> 'show error message or whatever
    >> Else
    >> 'print report or exit form or whatever
    >> End If
    >>
    >> Note that this will check ALL the Check Boxes on the form, if there are
    >> any
    >> that are not included in your checks then you will need to modify the
    >> function code accordingly. You could also modify the code to include
    >> multiple
    >> Text boxes, Combo boxes, etc. The reference codes for these would be
    >> acTextBox and acComboBox.
    >>
    >> Please let us know if this solves your problem, it may be helpful to
    >> other
    >> programmers.
    >> --
    >> Peter Hibbs
    >>
    >>

    >
    >
     
  20. BruceM

    BruceM
    Expand Collapse
    Guest

    Sorry, no handy links. I just sort of picked it up here and there. I
    believe a Google groups search will turn up quite a bit. I hadn't given it
    much thought before this question, but I think it could come in handy for
    form-level data validation. I expect I could use the Tag property to loop
    through required text boxes without having to name each one, but I'm not
    sure of the syntax. I'm just starting to experiment with it.

    "SusanV" <svanallen@nospam-mvps.org> wrote in message
    news:uaD0VfneGHA.3888@TK2MSFTNGP04.phx.gbl...
    > Hi Bruce,
    >
    > Do you have handy any links about the Tag Property for Access VBA? This
    > looks quite useful, I'd like to learn more about it - but all I can seem
    > to find on MSDN is info on using in DotNet.
    >
    > TIA,
    >
    > SusanV
    >
    > "BruceM" <bamoob@yawwhodawtcalm.not> wrote in message
    > news:uwHfkOneGHA.764@TK2MSFTNGP05.phx.gbl...
    >>I came up with something similar, but from a slightly different angle.
    >>The Tag property of the check boxes you want to test could be set to, say,
    >>2. Then you could have something like this in the form's Before Update
    >>event:
    >>
    >> Dim ctl As Control
    >> Dim blnChkBox As Boolean
    >>
    >> blnChkOK = False
    >>
    >> For Each ctl In Me.Controls
    >> If ctl.Tag = 2 Then
    >> If ctl.Value = -1 Then
    >> blnChkBox = True
    >> End If
    >> End If
    >> Next ctl
    >>
    >> If blnChkBox = False Then
    >> MsgBox "You need to check at least one box"
    >> Cancel = True
    >> End If
    >>
    >> In this way other check boxes can be ignored. However, if the only check
    >> boxes are the ones in question, control type can be used.
    >>
    >> To the person who posted the original question, an option group can be a
    >> good way of handling this sort of situation.
    >>
    >> "Peter Hibbs" <peter.hibbs@btinternet.com.NO_SPAM> wrote in message
    >> news:BC3A7152-EC06-4493-A098-8271D52CFBB2@microsoft.com...
    >>> JOM
    >>>
    >>> Just a quick recap, as I understand it you have 15 or more check boxes
    >>> on a
    >>> form and you want to allow the user to only do something if one or more
    >>> of
    >>> the boxes are ticked and you (quite rightly) do not want to have 15 or
    >>> so If
    >>> - Then statements in the code. If that is correct then try pasting the
    >>> following function code into your form module (not the dashes, of
    >>> course).
    >>>
    >>> ---------------------------------------------
    >>> Public Function ChecksOK() As Boolean
    >>>
    >>> 'Returns TRUE if ANY check box on current form is ticked, else returns
    >>> FALSE
    >>>
    >>> Dim cntl As Control
    >>>
    >>> For Each cntl In Me.Controls 'cycle thru all controls
    >>> on
    >>> form
    >>> If cntl.ControlType = acCheckBox Then 'if Control type =
    >>> CheckBox
    >>> then
    >>> If cntl = True Then ChecksOK = True 'if check box ticked then
    >>> ChecksOK = True
    >>> End If
    >>> Next cntl
    >>>
    >>> End Function
    >>> ---------------------------------------------
    >>>
    >>> You can then call the function like this :-
    >>>
    >>> If ChecksOK = False Then
    >>> 'show error message or whatever
    >>> Else
    >>> 'print report or exit form or whatever
    >>> End If
    >>>
    >>> Note that this will check ALL the Check Boxes on the form, if there are
    >>> any
    >>> that are not included in your checks then you will need to modify the
    >>> function code accordingly. You could also modify the code to include
    >>> multiple
    >>> Text boxes, Combo boxes, etc. The reference codes for these would be
    >>> acTextBox and acComboBox.
    >>>
    >>> Please let us know if this solves your problem, it may be helpful to
    >>> other
    >>> programmers.
    >>> --
    >>> Peter Hibbs
    >>>
    >>>

    >>
    >>

    >
    >
     
  21. SusanV

    SusanV
    Expand Collapse
    Guest

    Thanks for replying - I'll expand my search.

    HAGD!

    SusanV

    "BruceM" <bamoob@yawwhodawtcalm.not> wrote in message
    news:eYd1OBoeGHA.4892@TK2MSFTNGP02.phx.gbl...
    > Sorry, no handy links. I just sort of picked it up here and there. I
    > believe a Google groups search will turn up quite a bit. I hadn't given
    > it much thought before this question, but I think it could come in handy
    > for form-level data validation. I expect I could use the Tag property to
    > loop through required text boxes without having to name each one, but I'm
    > not sure of the syntax. I'm just starting to experiment with it.
    >
    > "SusanV" <svanallen@nospam-mvps.org> wrote in message
    > news:uaD0VfneGHA.3888@TK2MSFTNGP04.phx.gbl...
    >> Hi Bruce,
    >>
    >> Do you have handy any links about the Tag Property for Access VBA? This
    >> looks quite useful, I'd like to learn more about it - but all I can seem
    >> to find on MSDN is info on using in DotNet.
    >>
    >> TIA,
    >>
    >> SusanV
    >>
    >> "BruceM" <bamoob@yawwhodawtcalm.not> wrote in message
    >> news:uwHfkOneGHA.764@TK2MSFTNGP05.phx.gbl...
    >>>I came up with something similar, but from a slightly different angle.
    >>>The Tag property of the check boxes you want to test could be set to,
    >>>say, 2. Then you could have something like this in the form's Before
    >>>Update event:
    >>>
    >>> Dim ctl As Control
    >>> Dim blnChkBox As Boolean
    >>>
    >>> blnChkOK = False
    >>>
    >>> For Each ctl In Me.Controls
    >>> If ctl.Tag = 2 Then
    >>> If ctl.Value = -1 Then
    >>> blnChkBox = True
    >>> End If
    >>> End If
    >>> Next ctl
    >>>
    >>> If blnChkBox = False Then
    >>> MsgBox "You need to check at least one box"
    >>> Cancel = True
    >>> End If
    >>>
    >>> In this way other check boxes can be ignored. However, if the only
    >>> check boxes are the ones in question, control type can be used.
    >>>
    >>> To the person who posted the original question, an option group can be a
    >>> good way of handling this sort of situation.
    >>>
    >>> "Peter Hibbs" <peter.hibbs@btinternet.com.NO_SPAM> wrote in message
    >>> news:BC3A7152-EC06-4493-A098-8271D52CFBB2@microsoft.com...
    >>>> JOM
    >>>>
    >>>> Just a quick recap, as I understand it you have 15 or more check boxes
    >>>> on a
    >>>> form and you want to allow the user to only do something if one or more
    >>>> of
    >>>> the boxes are ticked and you (quite rightly) do not want to have 15 or
    >>>> so If
    >>>> - Then statements in the code. If that is correct then try pasting the
    >>>> following function code into your form module (not the dashes, of
    >>>> course).
    >>>>
    >>>> ---------------------------------------------
    >>>> Public Function ChecksOK() As Boolean
    >>>>
    >>>> 'Returns TRUE if ANY check box on current form is ticked, else returns
    >>>> FALSE
    >>>>
    >>>> Dim cntl As Control
    >>>>
    >>>> For Each cntl In Me.Controls 'cycle thru all controls
    >>>> on
    >>>> form
    >>>> If cntl.ControlType = acCheckBox Then 'if Control type =
    >>>> CheckBox
    >>>> then
    >>>> If cntl = True Then ChecksOK = True 'if check box ticked
    >>>> then
    >>>> ChecksOK = True
    >>>> End If
    >>>> Next cntl
    >>>>
    >>>> End Function
    >>>> ---------------------------------------------
    >>>>
    >>>> You can then call the function like this :-
    >>>>
    >>>> If ChecksOK = False Then
    >>>> 'show error message or whatever
    >>>> Else
    >>>> 'print report or exit form or whatever
    >>>> End If
    >>>>
    >>>> Note that this will check ALL the Check Boxes on the form, if there are
    >>>> any
    >>>> that are not included in your checks then you will need to modify the
    >>>> function code accordingly. You could also modify the code to include
    >>>> multiple
    >>>> Text boxes, Combo boxes, etc. The reference codes for these would be
    >>>> acTextBox and acComboBox.
    >>>>
    >>>> Please let us know if this solves your problem, it may be helpful to
    >>>> other
    >>>> programmers.
    >>>> --
    >>>> Peter Hibbs
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     

Share This Page