Change query from textbox on form

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

    Change query from textbox on form

    I have a form based on this query:


    SELECT Students.LastSe rDT, OtherInfo.Serve d, OtherInfo.HSGra dYr,
    OtherInfo.Activ ePart, OtherInfo.Serve d, Students.SSN, [LastNM] & ", " &
    [FirstNM] & " " & [MI] AS Name, Students.LastNM , Students.FirstN M,
    Students.MI, Students.DOB, Students.Gender CD, Students.Ethnic ityCD,
    Students.Eligib ilityCD, Students.UBInit iative, Students.NCESSc hID,
    Students.ProjEn tryDT, Students.ProjRe EntDT, Students.LastSe rDT,
    Students.Reason , Students.PartCD , Students.PartLV , Students.NeedCD ,
    Students.Assess CD, Students.PSAT, Students.PLAN, Students.EnterG radeLV,
    Students.EndGra deLV, Students.EntryG PAScale, Students.CumGPA Entry,
    Students.EndGPA Scale, Students.HSGPA1 , Students.HSGPA2 , Students.CollEx amCD,
    OtherInfo.NCESS chNM, OtherInfo.Middl eNM, OtherInfo.Curre ntGradeLV,
    OtherInfo.Curre ntHSNM, Students.Pictur ePath
    FROM Students LEFT JOIN OtherInfo ON Students.SSN = OtherInfo.SSN
    WHERE (((Students.Las tSerDT) Is Null)) OR (((OtherInfo.Se rved)=Yes)) OR
    ((([Forms]![frmStudents]![CheckCriteria])=Yes))
    ORDER BY Students.LastNM , Students.FirstN M;

    If [Forms]![frmStudents]![CheckCriteria]=No then it shows records WHERE
    Students.LastSe rDT Is Null OR OtherInfo.Serve d=Yes. (This is the default
    when the form is opened.) If [Forms]![frmStudents]![CheckCriteria]=Yes then
    it shows every record. It works just like I wanted.
    When I click the CheckCriteria checkbox this is called:

    Private Sub CheckCriteria_C lick()
    'if checkbox = yes then shows all students, else shows current/active
    Me.Requery
    Me.ComboStudent .Requery
    ShowName = ComboStudent.Co lumn(2)
    End Sub

    The ComboStudent combobox gets its information from the same query so that
    it shows the correct records.

    However, now the user wants the option of showing students with a particular
    HSGradYr. I have added a textbox called txtGradYear to my form for the user
    to enter a year, but I don't know where to go from here.

    I'm basically wanting this one query to act in 3 different ways.

    1. WHERE Students.LastSe rDT Is Null OR OtherInfo.Serve d=Yes

    2. WHERE [Forms]![frmStudents]![CheckCriteria]=Yes

    3. WHERE OtherInfo.HSGra dYr=[forms]![frmStudents]![txtGradYear]

    And I want the ComboStudent to display the appropriate entries for each
    WHERE.

    I've got it working the first 2 ways, but I cannot figure out how to get the
    3rd way to work. I tried:

    WHERE (Students.LastS erDT Is Null OR OtherInfo.Serve d=Yes) OR
    ([Forms]![frmStudents]![CheckCriteria]=Yes) OR
    (OtherInfo.HSGr adYr=[forms]![frmStudents]![txtGradYear])

    but I didn't get JUST the records where
    OtherInfo.HSGra dYr=[forms]![frmStudents]![txtGradYear] which makes sense.

    Can anyone help me get what I need?

    Thanks in advance,
    Debbie


  • Salad

    #2
    Re: Change query from textbox on form

    DebbieG wrote:
    [color=blue]
    > I have a form based on this query:
    >
    >
    > SELECT Students.LastSe rDT, OtherInfo.Serve d, OtherInfo.HSGra dYr,
    > OtherInfo.Activ ePart, OtherInfo.Serve d, Students.SSN, [LastNM] & ", " &
    > [FirstNM] & " " & [MI] AS Name, Students.LastNM , Students.FirstN M,
    > Students.MI, Students.DOB, Students.Gender CD, Students.Ethnic ityCD,
    > Students.Eligib ilityCD, Students.UBInit iative, Students.NCESSc hID,
    > Students.ProjEn tryDT, Students.ProjRe EntDT, Students.LastSe rDT,
    > Students.Reason , Students.PartCD , Students.PartLV , Students.NeedCD ,
    > Students.Assess CD, Students.PSAT, Students.PLAN, Students.EnterG radeLV,
    > Students.EndGra deLV, Students.EntryG PAScale, Students.CumGPA Entry,
    > Students.EndGPA Scale, Students.HSGPA1 , Students.HSGPA2 , Students.CollEx amCD,
    > OtherInfo.NCESS chNM, OtherInfo.Middl eNM, OtherInfo.Curre ntGradeLV,
    > OtherInfo.Curre ntHSNM, Students.Pictur ePath
    > FROM Students LEFT JOIN OtherInfo ON Students.SSN = OtherInfo.SSN
    > WHERE (((Students.Las tSerDT) Is Null)) OR (((OtherInfo.Se rved)=Yes)) OR
    > ((([Forms]![frmStudents]![CheckCriteria])=Yes))
    > ORDER BY Students.LastNM , Students.FirstN M;
    >
    > If [Forms]![frmStudents]![CheckCriteria]=No then it shows records WHERE
    > Students.LastSe rDT Is Null OR OtherInfo.Serve d=Yes. (This is the default
    > when the form is opened.) If [Forms]![frmStudents]![CheckCriteria]=Yes then
    > it shows every record. It works just like I wanted.
    > When I click the CheckCriteria checkbox this is called:
    >
    > Private Sub CheckCriteria_C lick()
    > 'if checkbox = yes then shows all students, else shows current/active
    > Me.Requery
    > Me.ComboStudent .Requery
    > ShowName = ComboStudent.Co lumn(2)
    > End Sub
    >
    > The ComboStudent combobox gets its information from the same query so that
    > it shows the correct records.
    >
    > However, now the user wants the option of showing students with a particular
    > HSGradYr. I have added a textbox called txtGradYear to my form for the user
    > to enter a year, but I don't know where to go from here.
    >
    > I'm basically wanting this one query to act in 3 different ways.
    >
    > 1. WHERE Students.LastSe rDT Is Null OR OtherInfo.Serve d=Yes
    >
    > 2. WHERE [Forms]![frmStudents]![CheckCriteria]=Yes
    >
    > 3. WHERE OtherInfo.HSGra dYr=[forms]![frmStudents]![txtGradYear]
    >
    > And I want the ComboStudent to display the appropriate entries for each
    > WHERE.
    >
    > I've got it working the first 2 ways, but I cannot figure out how to get the
    > 3rd way to work. I tried:
    >
    > WHERE (Students.LastS erDT Is Null OR OtherInfo.Serve d=Yes) OR
    > ([Forms]![frmStudents]![CheckCriteria]=Yes) OR
    > (OtherInfo.HSGr adYr=[forms]![frmStudents]![txtGradYear])
    >
    > but I didn't get JUST the records where
    > OtherInfo.HSGra dYr=[forms]![frmStudents]![txtGradYear] which makes sense.
    >
    > Can anyone help me get what I need?
    >
    > Thanks in advance,
    > Debbie
    >
    >[/color]
    Sometimes what I might do is create a rowsource for a combo without a
    filter. Ex:
    Select EmpID, EmployeeID from Employees;

    I may have a invisible field, I'll call it RowSourceString , on the form
    to hold am text value string. When I open the form I enter some code in
    the OnOpen event similar to the following

    Sub Form_OnOpen
    'get the combo boxes rowsource. has no filter or orderby
    Me.RowSourceStr ing = Me.ComboboxName .RowSource

    'remove the semi-colon if it exists since a ; terminates
    'a SQL statement.
    If right(Me.RowSou rceString,1) = ";" Then
    Me.RowSourceStr ing = Left(Me.RowSour ceString,Len(Me .RowSourceStrin g)-1)
    Endif
    End Sub

    Now whenever values change I can put something in the afterupdate event
    of that field to create the filter. Let's say the code field has changed.
    Sub Code_AfterUpdat e
    Dim strWhere As String

    'create the filter. Remember...quot es around
    'text fields, # around dates, nothing around numbers
    StrWHere = "Where Code = " & Me.Code
    'you can add more filtering to this string

    'now update the combo box rowsource
    Me.ComboBoxName .RowSource = Me.RowSourceStr ing & _
    strWhere & " Order By Whatever"
    End Sub



    Comment

    • DebbieG

      #3
      Re: Change query from textbox on form


      "Salad" <oil@vinegar.co m> wrote in message
      news:VhWec.8198 $A_4.4477@newsr ead1.news.pas.e arthlink.net...
      DebbieG wrote:
      [color=blue]
      > I have a form based on this query:
      >
      >
      > SELECT Students.LastSe rDT, OtherInfo.Serve d, OtherInfo.HSGra dYr,
      > OtherInfo.Activ ePart, OtherInfo.Serve d, Students.SSN, [LastNM] & ", " &
      > [FirstNM] & " " & [MI] AS Name, Students.LastNM , Students.FirstN M,
      > Students.MI, Students.DOB, Students.Gender CD, Students.Ethnic ityCD,
      > Students.Eligib ilityCD, Students.UBInit iative, Students.NCESSc hID,
      > Students.ProjEn tryDT, Students.ProjRe EntDT, Students.LastSe rDT,
      > Students.Reason , Students.PartCD , Students.PartLV , Students.NeedCD ,
      > Students.Assess CD, Students.PSAT, Students.PLAN, Students.EnterG radeLV,
      > Students.EndGra deLV, Students.EntryG PAScale, Students.CumGPA Entry,
      > Students.EndGPA Scale, Students.HSGPA1 , Students.HSGPA2 ,[/color]
      Students.CollEx amCD,[color=blue]
      > OtherInfo.NCESS chNM, OtherInfo.Middl eNM, OtherInfo.Curre ntGradeLV,
      > OtherInfo.Curre ntHSNM, Students.Pictur ePath
      > FROM Students LEFT JOIN OtherInfo ON Students.SSN = OtherInfo.SSN
      > WHERE (((Students.Las tSerDT) Is Null)) OR (((OtherInfo.Se rved)=Yes)) OR
      > ((([Forms]![frmStudents]![CheckCriteria])=Yes))
      > ORDER BY Students.LastNM , Students.FirstN M;
      >
      > If [Forms]![frmStudents]![CheckCriteria]=No then it shows records WHERE
      > Students.LastSe rDT Is Null OR OtherInfo.Serve d=Yes. (This is the default
      > when the form is opened.) If [Forms]![frmStudents]![CheckCriteria]=Yes[/color]
      then[color=blue]
      > it shows every record. It works just like I wanted.
      > When I click the CheckCriteria checkbox this is called:
      >
      > Private Sub CheckCriteria_C lick()
      > 'if checkbox = yes then shows all students, else shows current/active
      > Me.Requery
      > Me.ComboStudent .Requery
      > ShowName = ComboStudent.Co lumn(2)
      > End Sub
      >
      > The ComboStudent combobox gets its information from the same query so that
      > it shows the correct records.
      >
      > However, now the user wants the option of showing students with a[/color]
      particular[color=blue]
      > HSGradYr. I have added a textbox called txtGradYear to my form for the[/color]
      user[color=blue]
      > to enter a year, but I don't know where to go from here.
      >
      > I'm basically wanting this one query to act in 3 different ways.
      >
      > 1. WHERE Students.LastSe rDT Is Null OR OtherInfo.Serve d=Yes
      >
      > 2. WHERE [Forms]![frmStudents]![CheckCriteria]=Yes
      >
      > 3. WHERE OtherInfo.HSGra dYr=[forms]![frmStudents]![txtGradYear]
      >
      > And I want the ComboStudent to display the appropriate entries for each
      > WHERE.
      >
      > I've got it working the first 2 ways, but I cannot figure out how to get[/color]
      the[color=blue]
      > 3rd way to work. I tried:
      >
      > WHERE (Students.LastS erDT Is Null OR OtherInfo.Serve d=Yes) OR
      > ([Forms]![frmStudents]![CheckCriteria]=Yes) OR
      > (OtherInfo.HSGr adYr=[forms]![frmStudents]![txtGradYear])
      >
      > but I didn't get JUST the records where
      > OtherInfo.HSGra dYr=[forms]![frmStudents]![txtGradYear] which makes sense.
      >
      > Can anyone help me get what I need?
      >
      > Thanks in advance,
      > Debbie
      >
      >[/color]
      Sometimes what I might do is create a rowsource for a combo without a
      filter. Ex:
      Select EmpID, EmployeeID from Employees;

      I may have a invisible field, I'll call it RowSourceString , on the form
      to hold am text value string. When I open the form I enter some code in
      the OnOpen event similar to the following

      Sub Form_OnOpen
      'get the combo boxes rowsource. has no filter or orderby
      Me.RowSourceStr ing = Me.ComboboxName .RowSource

      'remove the semi-colon if it exists since a ; terminates
      'a SQL statement.
      If right(Me.RowSou rceString,1) = ";" Then
      Me.RowSourceStr ing = Left(Me.RowSour ceString,Len(Me .RowSourceStrin g)-1)
      Endif
      End Sub

      Now whenever values change I can put something in the afterupdate event
      of that field to create the filter. Let's say the code field has changed.
      Sub Code_AfterUpdat e
      Dim strWhere As String

      'create the filter. Remember...quot es around
      'text fields, # around dates, nothing around numbers
      StrWHere = "Where Code = " & Me.Code
      'you can add more filtering to this string

      'now update the combo box rowsource
      Me.ComboBoxName .RowSource = Me.RowSourceStr ing & _
      strWhere & " Order By Whatever"
      End Sub
      *************** *************** *************** *************** ***********

      Thanks so much for your response. I couldn't get my query to work the way I
      wanted but you led me in the right path. This is what I did:

      Private Sub txtGradYear_Exi t(Cancel As Integer)
      Dim x As Variant
      x = DCount("*", "OtherInfo" , "HSGradYr = " & Me.txtGradYear)
      If x = 0 Then
      msg1 = "There are no students in this graduation year."
      Response = MsgBox(msg1, vbExclamation, conTitle)
      DoCmd.GoToContr ol "txtGradYea r"
      Exit Sub
      End If

      Me.CheckCurrent = False 'based on qselStudents
      Me.CheckCriteri a = False 'based on qselStudents

      Forms!frmStuden ts.RecordSource = "qselStuden ts2"

      Dim strNewSource
      strNewSource = "SELECT qselStudents2.S SN, " _
      & "Format([SSN],""000-00-0000"") AS Expr1, " _
      & "qselStudents2. Name " _
      & "FROM qselStudents2;"
      Me.ComboStudent .RowSourceType = "Table/Query"
      Me.ComboStudent .RowSource = strNewSource

      Me.Requery
      Me.ComboStudent .Requery
      ShowName = ComboStudent.Co lumn(2)
      End Sub

      Is putting this in _Exit the best way to go with this? If not, what do you
      recommend?

      Thanks so much,
      Debbie

      Comment

      • Salad

        #4
        Re: Change query from textbox on form

        DebbieG wrote:
        [color=blue]
        > "Salad" <oil@vinegar.co m> wrote in message
        > news:VhWec.8198 $A_4.4477@newsr ead1.news.pas.e arthlink.net...
        > DebbieG wrote:
        >
        >[color=green]
        >>I have a form based on this query:
        >>
        >>
        >>SELECT Students.LastSe rDT, OtherInfo.Serve d, OtherInfo.HSGra dYr,
        >>OtherInfo.Act ivePart, OtherInfo.Serve d, Students.SSN, [LastNM] & ", " &
        >>[FirstNM] & " " & [MI] AS Name, Students.LastNM , Students.FirstN M,
        >>Students.MI , Students.DOB, Students.Gender CD, Students.Ethnic ityCD,
        >>Students.Elig ibilityCD, Students.UBInit iative, Students.NCESSc hID,
        >>Students.Proj EntryDT, Students.ProjRe EntDT, Students.LastSe rDT,
        >>Students.Reas on, Students.PartCD , Students.PartLV , Students.NeedCD ,
        >>Students.Asse ssCD, Students.PSAT, Students.PLAN, Students.EnterG radeLV,
        >>Students.EndG radeLV, Students.EntryG PAScale, Students.CumGPA Entry,
        >>Students.EndG PAScale, Students.HSGPA1 , Students.HSGPA2 ,[/color]
        >
        > Students.CollEx amCD,
        >[color=green]
        >>OtherInfo.NCE SSchNM, OtherInfo.Middl eNM, OtherInfo.Curre ntGradeLV,
        >>OtherInfo.Cur rentHSNM, Students.Pictur ePath
        >>FROM Students LEFT JOIN OtherInfo ON Students.SSN = OtherInfo.SSN
        >>WHERE (((Students.Las tSerDT) Is Null)) OR (((OtherInfo.Se rved)=Yes)) OR
        >>((([Forms]![frmStudents]![CheckCriteria])=Yes))
        >>ORDER BY Students.LastNM , Students.FirstN M;
        >>
        >>If [Forms]![frmStudents]![CheckCriteria]=No then it shows records WHERE
        >>Students.Last SerDT Is Null OR OtherInfo.Serve d=Yes. (This is the default
        >>when the form is opened.) If [Forms]![frmStudents]![CheckCriteria]=Yes[/color]
        >
        > then
        >[color=green]
        >>it shows every record. It works just like I wanted.
        >>When I click the CheckCriteria checkbox this is called:
        >>
        >>Private Sub CheckCriteria_C lick()
        >> 'if checkbox = yes then shows all students, else shows current/active
        >> Me.Requery
        >> Me.ComboStudent .Requery
        >> ShowName = ComboStudent.Co lumn(2)
        >>End Sub
        >>
        >>The ComboStudent combobox gets its information from the same query so that
        >>it shows the correct records.
        >>
        >>However, now the user wants the option of showing students with a[/color]
        >
        > particular
        >[color=green]
        >>HSGradYr. I have added a textbox called txtGradYear to my form for the[/color]
        >
        > user
        >[color=green]
        >>to enter a year, but I don't know where to go from here.
        >>
        >>I'm basically wanting this one query to act in 3 different ways.
        >>
        >>1. WHERE Students.LastSe rDT Is Null OR OtherInfo.Serve d=Yes
        >>
        >>2. WHERE [Forms]![frmStudents]![CheckCriteria]=Yes
        >>
        >>3. WHERE OtherInfo.HSGra dYr=[forms]![frmStudents]![txtGradYear]
        >>
        >>And I want the ComboStudent to display the appropriate entries for each
        >>WHERE.
        >>
        >>I've got it working the first 2 ways, but I cannot figure out how to get[/color]
        >
        > the
        >[color=green]
        >>3rd way to work. I tried:
        >>
        >>WHERE (Students.LastS erDT Is Null OR OtherInfo.Serve d=Yes) OR
        >>([Forms]![frmStudents]![CheckCriteria]=Yes) OR
        >>(OtherInfo.HS GradYr=[forms]![frmStudents]![txtGradYear])
        >>
        >>but I didn't get JUST the records where
        >>OtherInfo.HSG radYr=[forms]![frmStudents]![txtGradYear] which makes sense.
        >>
        >>Can anyone help me get what I need?
        >>
        >>Thanks in advance,
        >>Debbie
        >>
        >>[/color]
        >
        > Sometimes what I might do is create a rowsource for a combo without a
        > filter. Ex:
        > Select EmpID, EmployeeID from Employees;
        >
        > I may have a invisible field, I'll call it RowSourceString , on the form
        > to hold am text value string. When I open the form I enter some code in
        > the OnOpen event similar to the following
        >
        > Sub Form_OnOpen
        > 'get the combo boxes rowsource. has no filter or orderby
        > Me.RowSourceStr ing = Me.ComboboxName .RowSource
        >
        > 'remove the semi-colon if it exists since a ; terminates
        > 'a SQL statement.
        > If right(Me.RowSou rceString,1) = ";" Then
        > Me.RowSourceStr ing = Left(Me.RowSour ceString,Len(Me .RowSourceStrin g)-1)
        > Endif
        > End Sub
        >
        > Now whenever values change I can put something in the afterupdate event
        > of that field to create the filter. Let's say the code field has changed.
        > Sub Code_AfterUpdat e
        > Dim strWhere As String
        >
        > 'create the filter. Remember...quot es around
        > 'text fields, # around dates, nothing around numbers
        > StrWHere = "Where Code = " & Me.Code
        > 'you can add more filtering to this string
        >
        > 'now update the combo box rowsource
        > Me.ComboBoxName .RowSource = Me.RowSourceStr ing & _
        > strWhere & " Order By Whatever"
        > End Sub
        > *************** *************** *************** *************** ***********
        >
        > Thanks so much for your response. I couldn't get my query to work the way I
        > wanted but you led me in the right path. This is what I did:
        >
        > Private Sub txtGradYear_Exi t(Cancel As Integer)
        > Dim x As Variant
        > x = DCount("*", "OtherInfo" , "HSGradYr = " & Me.txtGradYear)
        > If x = 0 Then
        > msg1 = "There are no students in this graduation year."
        > Response = MsgBox(msg1, vbExclamation, conTitle)
        > DoCmd.GoToContr ol "txtGradYea r"
        > Exit Sub
        > End If
        >
        >[/color]
        You could put the code from the Dim to Endif in the BeforeUpdate event.
        I have used code like the following in the past
        IF x = 0 then
        DoCmd.RunComman d acCmdUndo
        SendKeys "{ESC}"
        Cancel = True
        End If

        This will clear out the data that was entered by using the SendKeys. Or
        you could simply state
        Cancel = True

        Then put the rest of the code in the AfterUpdate event. You would want
        to check in the AfterUpdate that year is not blank though.

        Does qselStudents2 filter on the Year? IOW, does it contain a query to
        do the filter you need?

        BTW, You don't need to requery if you create a new rowsource.

        Oftentimes I do something like
        Select qselStudents2.S SN, _
        Format([SSN],""000-00-0000"") AS [Soc Sec]
        because I turn column headings on. Displaying Expr1 can confuse people.
        Just a hint for the future if you turn column headings on

        [color=blue]
        >
        > Me.CheckCurrent = False 'based on qselStudents
        > Me.CheckCriteri a = False 'based on qselStudents
        >
        > Forms!frmStuden ts.RecordSource = "qselStuden ts2"
        >
        > Dim strNewSource
        > strNewSource = "SELECT qselStudents2.S SN, " _
        > & "Format([SSN],""000-00-0000"") AS Expr1, " _
        > & "qselStudents2. Name " _
        > & "FROM qselStudents2;"
        > Me.ComboStudent .RowSourceType = "Table/Query"
        > Me.ComboStudent .RowSource = strNewSource
        >
        > Me.Requery
        > Me.ComboStudent .Requery
        > ShowName = ComboStudent.Co lumn(2)
        > End Sub
        >
        > Is putting this in _Exit the best way to go with this? If not, what[/color]
        do you[color=blue]
        > recommend?[/color]

        I always do what works. If it works for you then that is fine. I do
        most of my error validation in BeforeUpdate and execute pass code in the
        AfterUpdate.

        Ain't debugging fun?
        [color=blue]
        >
        > Thanks so much,
        > Debbie
        >[/color]


        Comment

        • DebbieG

          #5
          Re: Change query from textbox on form

          Thank you!
          Debbie

          "Salad" <oil@vinegar.co m> wrote in message
          news:Weafc.9706 $A_4.2081@newsr ead1.news.pas.e arthlink.net...
          DebbieG wrote:
          [color=blue]
          > "Salad" <oil@vinegar.co m> wrote in message
          > news:VhWec.8198 $A_4.4477@newsr ead1.news.pas.e arthlink.net...
          > DebbieG wrote:
          >
          >[color=green]
          >>I have a form based on this query:
          >>
          >>
          >>SELECT Students.LastSe rDT, OtherInfo.Serve d, OtherInfo.HSGra dYr,
          >>OtherInfo.Act ivePart, OtherInfo.Serve d, Students.SSN, [LastNM] & ", " &
          >>[FirstNM] & " " & [MI] AS Name, Students.LastNM , Students.FirstN M,
          >>Students.MI , Students.DOB, Students.Gender CD, Students.Ethnic ityCD,
          >>Students.Elig ibilityCD, Students.UBInit iative, Students.NCESSc hID,
          >>Students.Proj EntryDT, Students.ProjRe EntDT, Students.LastSe rDT,
          >>Students.Reas on, Students.PartCD , Students.PartLV , Students.NeedCD ,
          >>Students.Asse ssCD, Students.PSAT, Students.PLAN, Students.EnterG radeLV,
          >>Students.EndG radeLV, Students.EntryG PAScale, Students.CumGPA Entry,
          >>Students.EndG PAScale, Students.HSGPA1 , Students.HSGPA2 ,[/color]
          >
          > Students.CollEx amCD,
          >[color=green]
          >>OtherInfo.NCE SSchNM, OtherInfo.Middl eNM, OtherInfo.Curre ntGradeLV,
          >>OtherInfo.Cur rentHSNM, Students.Pictur ePath
          >>FROM Students LEFT JOIN OtherInfo ON Students.SSN = OtherInfo.SSN
          >>WHERE (((Students.Las tSerDT) Is Null)) OR (((OtherInfo.Se rved)=Yes)) OR
          >>((([Forms]![frmStudents]![CheckCriteria])=Yes))
          >>ORDER BY Students.LastNM , Students.FirstN M;
          >>
          >>If [Forms]![frmStudents]![CheckCriteria]=No then it shows records WHERE
          >>Students.Last SerDT Is Null OR OtherInfo.Serve d=Yes. (This is the default
          >>when the form is opened.) If [Forms]![frmStudents]![CheckCriteria]=Yes[/color]
          >
          > then
          >[color=green]
          >>it shows every record. It works just like I wanted.
          >>When I click the CheckCriteria checkbox this is called:
          >>
          >>Private Sub CheckCriteria_C lick()
          >> 'if checkbox = yes then shows all students, else shows current/active
          >> Me.Requery
          >> Me.ComboStudent .Requery
          >> ShowName = ComboStudent.Co lumn(2)
          >>End Sub
          >>
          >>The ComboStudent combobox gets its information from the same query so that
          >>it shows the correct records.
          >>
          >>However, now the user wants the option of showing students with a[/color]
          >
          > particular
          >[color=green]
          >>HSGradYr. I have added a textbox called txtGradYear to my form for the[/color]
          >
          > user
          >[color=green]
          >>to enter a year, but I don't know where to go from here.
          >>
          >>I'm basically wanting this one query to act in 3 different ways.
          >>
          >>1. WHERE Students.LastSe rDT Is Null OR OtherInfo.Serve d=Yes
          >>
          >>2. WHERE [Forms]![frmStudents]![CheckCriteria]=Yes
          >>
          >>3. WHERE OtherInfo.HSGra dYr=[forms]![frmStudents]![txtGradYear]
          >>
          >>And I want the ComboStudent to display the appropriate entries for each
          >>WHERE.
          >>
          >>I've got it working the first 2 ways, but I cannot figure out how to get[/color]
          >
          > the
          >[color=green]
          >>3rd way to work. I tried:
          >>
          >>WHERE (Students.LastS erDT Is Null OR OtherInfo.Serve d=Yes) OR
          >>([Forms]![frmStudents]![CheckCriteria]=Yes) OR
          >>(OtherInfo.HS GradYr=[forms]![frmStudents]![txtGradYear])
          >>
          >>but I didn't get JUST the records where
          >>OtherInfo.HSG radYr=[forms]![frmStudents]![txtGradYear] which makes sense.
          >>
          >>Can anyone help me get what I need?
          >>
          >>Thanks in advance,
          >>Debbie
          >>
          >>[/color]
          >
          > Sometimes what I might do is create a rowsource for a combo without a
          > filter. Ex:
          > Select EmpID, EmployeeID from Employees;
          >
          > I may have a invisible field, I'll call it RowSourceString , on the form
          > to hold am text value string. When I open the form I enter some code in
          > the OnOpen event similar to the following
          >
          > Sub Form_OnOpen
          > 'get the combo boxes rowsource. has no filter or orderby
          > Me.RowSourceStr ing = Me.ComboboxName .RowSource
          >
          > 'remove the semi-colon if it exists since a ; terminates
          > 'a SQL statement.
          > If right(Me.RowSou rceString,1) = ";" Then
          > Me.RowSourceStr ing = Left(Me.RowSour ceString,Len(Me .RowSourceStrin g)-1)
          > Endif
          > End Sub
          >
          > Now whenever values change I can put something in the afterupdate event
          > of that field to create the filter. Let's say the code field has changed.
          > Sub Code_AfterUpdat e
          > Dim strWhere As String
          >
          > 'create the filter. Remember...quot es around
          > 'text fields, # around dates, nothing around numbers
          > StrWHere = "Where Code = " & Me.Code
          > 'you can add more filtering to this string
          >
          > 'now update the combo box rowsource
          > Me.ComboBoxName .RowSource = Me.RowSourceStr ing & _
          > strWhere & " Order By Whatever"
          > End Sub
          > *************** *************** *************** *************** ***********
          >
          > Thanks so much for your response. I couldn't get my query to work the way[/color]
          I[color=blue]
          > wanted but you led me in the right path. This is what I did:
          >
          > Private Sub txtGradYear_Exi t(Cancel As Integer)
          > Dim x As Variant
          > x = DCount("*", "OtherInfo" , "HSGradYr = " & Me.txtGradYear)
          > If x = 0 Then
          > msg1 = "There are no students in this graduation year."
          > Response = MsgBox(msg1, vbExclamation, conTitle)
          > DoCmd.GoToContr ol "txtGradYea r"
          > Exit Sub
          > End If
          >
          >[/color]
          You could put the code from the Dim to Endif in the BeforeUpdate event.
          I have used code like the following in the past
          IF x = 0 then
          DoCmd.RunComman d acCmdUndo
          SendKeys "{ESC}"
          Cancel = True
          End If

          This will clear out the data that was entered by using the SendKeys. Or
          you could simply state
          Cancel = True

          Then put the rest of the code in the AfterUpdate event. You would want
          to check in the AfterUpdate that year is not blank though.

          Does qselStudents2 filter on the Year? IOW, does it contain a query to
          do the filter you need?

          BTW, You don't need to requery if you create a new rowsource.

          Oftentimes I do something like
          Select qselStudents2.S SN, _
          Format([SSN],""000-00-0000"") AS [Soc Sec]
          because I turn column headings on. Displaying Expr1 can confuse people.
          Just a hint for the future if you turn column headings on

          [color=blue]
          >
          > Me.CheckCurrent = False 'based on qselStudents
          > Me.CheckCriteri a = False 'based on qselStudents
          >
          > Forms!frmStuden ts.RecordSource = "qselStuden ts2"
          >
          > Dim strNewSource
          > strNewSource = "SELECT qselStudents2.S SN, " _
          > & "Format([SSN],""000-00-0000"") AS Expr1, " _
          > & "qselStudents2. Name " _
          > & "FROM qselStudents2;"
          > Me.ComboStudent .RowSourceType = "Table/Query"
          > Me.ComboStudent .RowSource = strNewSource
          >
          > Me.Requery
          > Me.ComboStudent .Requery
          > ShowName = ComboStudent.Co lumn(2)
          > End Sub
          >
          > Is putting this in _Exit the best way to go with this? If not, what[/color]
          do you[color=blue]
          > recommend?[/color]

          I always do what works. If it works for you then that is fine. I do
          most of my error validation in BeforeUpdate and execute pass code in the
          AfterUpdate.

          Ain't debugging fun?
          [color=blue]
          >
          > Thanks so much,
          > Debbie
          >[/color]


          Comment

          Working...