VBA Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith

    VBA Question

    A97, NT4.

    I've inherited a database from a rather talented software developer and
    some of his code scares me ;-)

    One of the things I'm trying to understand is his custom "filter by form"
    utility.

    When the form is loaded, "acCmdFilterByF orm" is executed.

    Below is the code from the "On Apply Filter" event of the form. Could
    someone please tell me how "ApplyType" (one of the arguments) gets a value
    of 1? "ApplyType" isn't referenced anywhere else except for in this code
    and no arguments are passed when the form is called.

    Many thanks,
    Keith.

    Private Sub Form_ApplyFilte r(Cancel As Integer, ApplyType As Integer)
    ' Only apply filter if explicity requested from the Shortcut Menu
    '
    ' We have to update the caller from here because we can't
    ' Filter by Form from a dialog
    On Error GoTo errTrap

    ' Procedure name
    Const cProcedure = "Form_ApplyFilt er"

    Dim frm As Form

    If libIsFormLoaded (gcFrmProgress) Then
    Set frm = Forms(gcFrmProg ress)

    If ApplyType = acApplyFilter And libIsFormLoaded (gcFrmProgress)
    Then
    frm!cmdAdvanced .SetFocus
    frm!cboFilter.E nabled = False
    frm!txtFilterDe scription.Enabl ed = False
    frm!txtFilterDe scription.Locke d = False
    frm!shpFilter.V isible = False
    frm!cboItem.Row Source = "SELECT ItemID, Description, Area,
    Type, SeatOwner, Status, Deleted FROM " & Me.RecordSource _
    & " WHERE " & Me.Filter & " ORDER BY ItemID"
    ' frm!cboItem.Row Source = "SELECT DISTINCT tblItem.ItemID,
    tblItem.Descrip tion, tblItem.Area, tblItem.Type, tblItem.SeatOwn er,
    tblItem.Status, tblItem.Deleted FROM (tblItem INNER JOIN tblTask ON
    tblItem.ItemID = tblTask.ItemID) INNER JOIN qfrmProgress ON tblItem.ItemID
    = qfrmProgress.It emID WHERE (((tblTask.OpCo de) Not Like 'B*') AND
    ((tblTask.Progr ess)<1) AND ((tblTask.Appli cable)=True) AND " & Me.Filter &
    ") ORDER BY ItemID"
    frm!cboItem = frm!cboItem.Ite mData(0)
    frm!sfrProgress .LinkMasterFiel ds = "cboItem"
    frm!sfrProgress .LinkChildField s = "ItemID"
    frm.RefreshItem Details
    frm.ControlStat e
    ' frm.Requery
    frm.Filtered = True
    ElseIf ApplyType = acCloseFilterWi ndow Then
    frm.Filtered = False
    End If
    Set frm = Nothing
    End If

    ' Save filter (users do not have write access)
    gFilter = Me.Filter

    ' Close form
    DoCmd.Close acForm, Me.Name
    Exit Sub
  • Matthias Klaey

    #2
    Re: VBA Question

    Keith <keith.wilby@Aw ayWithYerCrap.c om> wrote:
    [color=blue]
    >A97, NT4.
    >
    >I've inherited a database from a rather talented software developer and
    >some of his code scares me ;-)
    >
    >One of the things I'm trying to understand is his custom "filter by form"
    >utility.
    >
    >When the form is loaded, "acCmdFilterByF orm" is executed.
    >
    >Below is the code from the "On Apply Filter" event of the form. Could
    >someone please tell me how "ApplyType" (one of the arguments) gets a value
    >of 1? "ApplyType" isn't referenced anywhere else except for in this code
    >and no arguments are passed when the form is called.
    >
    >Many thanks,
    >Keith.
    >
    >Private Sub Form_ApplyFilte r(Cancel As Integer, ApplyType As Integer)
    >' Only apply filter if explicity requested from the Shortcut Menu
    >'[/color]
    [...]

    The value of ApplyType is filled in by the caller of this event, which
    occurs e.g. if the user selects "Apply Filter" on the menu, but also
    if the user selects "remove filter/sort" on the menu.
    Possible values are: acShowAllRecord s = 0 and acApplyFilter = 1

    HTH
    Matthias Kläy
    --
    Internet, Telefonie, TV, Webhosting, Cloud, E-Mail, Backup & Business Connectivity


    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

    Comment

    • Keith

      #3
      Re: VBA Question

      Matthias Klaey <mpky@hotmail.c om> wrote:
      [color=blue]
      > The value of ApplyType is filled in by the caller of this event, which
      > occurs e.g. if the user selects "Apply Filter" on the menu, but also
      > if the user selects "remove filter/sort" on the menu.
      > Possible values are: acShowAllRecord s = 0 and acApplyFilter = 1
      >
      > HTH
      > Matthias Kläy[/color]

      Hi Matthias and many thanks for your response. I understand now - I
      originally thought that my predecessor had declared an ApplyType variable
      himself, I now realise that it is a default argument.

      Thaks again.
      Keith.

      Comment

      • Trevor Best

        #4
        Re: VBA Question

        Keith wrote:[color=blue]
        > Matthias Klaey <mpky@hotmail.c om> wrote:
        >
        >[color=green]
        >>The value of ApplyType is filled in by the caller of this event, which
        >>occurs e.g. if the user selects "Apply Filter" on the menu, but also
        >>if the user selects "remove filter/sort" on the menu.
        >>Possible values are: acShowAllRecord s = 0 and acApplyFilter = 1
        >>
        >>HTH
        >>Matthias Kläy[/color]
        >
        >
        > Hi Matthias and many thanks for your response. I understand now - I
        > originally thought that my predecessor had declared an ApplyType variable
        > himself, I now realise that it is a default argument.[/color]

        If like me (and many others here) the developer used naming conventions
        for his/her variables, you can tell the built in Access events by the
        fact that they don't have naming conventions applied on the parameters :-)

        --
        This sig left intentionally blank

        Comment

        • Grumpy Old Man

          #5
          Re: VBA Question

          Trevor Best <nospam@besty.o rg.uk> wrote:
          [color=blue][color=green]
          >> Hi Matthias and many thanks for your response. I understand now - I
          >> originally thought that my predecessor had declared an ApplyType
          >> variable himself, I now realise that it is a default argument.[/color]
          >
          > If like me (and many others here) the developer used naming conventions
          > for his/her variables, you can tell the built in Access events by the
          > fact that they don't have naming conventions applied on the parameters
          > :-)[/color]

          Yes I should have realised really. Like I say some of that code scares me
          (he was a software engineer, I'm not) and there's lots of it for me to wade
          though and understand :o)

          Comment

          Working...