Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filter on selection. (2000)

    God I'm having a bad day today....................

    I have a Form, FrmStartUp, with a combobox, CboArea. Its record source is: SELECT [TblArea].[AreaID], [TblArea].[AreaName] FROM [TblArea];

    CboArea looks up data from TblArea. TblArea has two fields AreaID (PK, Long Integer) and AreaName (Text).

    I then have a command button on FrmStartUp with:

    Private Sub CmdStart_Click()
    If Me.CboArea = Null Then
    MsgBox "No Area has been selected", vbInformation, "Error"
    Exit Sub
    End If
    DoCmd.OpenForm "FrmMain", , , "[AreaID] = " & Chr(34) & Me.CboArea & Chr(34), , , Me.CboArea
    Exit_CmdStart_Click:
    Exit Sub
    Err_CmdStart_Click:
    MsgBox "No Area has been selected", vbExclamation + vbOKOnly, "Please Amend"
    Resume Exit_CmdStart_Click
    End Sub

    What I'm trying to do is record the selection made in CboArea in FrmMain, field AreaID. Also filtering on that selection......

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Filter on selection. (2000)

    Instead of

    If Me.CboArea = Null Then

    use

    If IsNull(Me.CboArea) Then

    Since AreaID is a number field, not a text field you should omit the Chr(34)s - quotes are only needed to delimit text strings.

    DoCmd.OpenForm "FrmMain", , , "[AreaID] = " & Me.CboArea, , , Me.CboArea

  3. #3
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filter on selection. (2000)

    You're a star, I've got a meeting this afternoon to explain how to use it!!!!!

    I've also got an Open Argument on the main form:

    Me.[AreaID].DefaultValue = Chr(34) & Me.OpenArgs & Chr(34)

    Should this also be changed to
    Me.[AreaID].DefaultValue=Me.OpenArgs

    Basically filtering on AreaID.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Filter on selection. (2000)

    Same principle.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •