Change query from textbox on form | | |
I have a form based on this query:
SELECT Students.LastSerDT, OtherInfo.Served, OtherInfo.HSGradYr,
OtherInfo.ActivePart, OtherInfo.Served, Students.SSN, [LastNM] & ", " &
[FirstNM] & " " & [MI] AS Name, Students.LastNM, Students.FirstNM,
Students.MI, Students.DOB, Students.GenderCD, Students.EthnicityCD,
Students.EligibilityCD, Students.UBInitiative, Students.NCESSchID,
Students.ProjEntryDT, Students.ProjReEntDT, Students.LastSerDT,
Students.Reason, Students.PartCD, Students.PartLV, Students.NeedCD,
Students.AssessCD, Students.PSAT, Students.PLAN, Students.EnterGradeLV,
Students.EndGradeLV, Students.EntryGPAScale, Students.CumGPAEntry,
Students.EndGPAScale, Students.HSGPA1, Students.HSGPA2, Students.CollExamCD,
OtherInfo.NCESSchNM, OtherInfo.MiddleNM, OtherInfo.CurrentGradeLV,
OtherInfo.CurrentHSNM, Students.PicturePath
FROM Students LEFT JOIN OtherInfo ON Students.SSN = OtherInfo.SSN
WHERE (((Students.LastSerDT) Is Null)) OR (((OtherInfo.Served)=Yes)) OR
((([Forms]![frmStudents]![CheckCriteria])=Yes))
ORDER BY Students.LastNM, Students.FirstNM;
If [Forms]![frmStudents]![CheckCriteria]=No then it shows records WHERE
Students.LastSerDT Is Null OR OtherInfo.Served=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_Click()
'if checkbox = yes then shows all students, else shows current/active
Me.Requery
Me.ComboStudent.Requery
ShowName = ComboStudent.Column(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.LastSerDT Is Null OR OtherInfo.Served=Yes
2. WHERE [Forms]![frmStudents]![CheckCriteria]=Yes
3. WHERE OtherInfo.HSGradYr=[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.LastSerDT Is Null OR OtherInfo.Served=Yes) OR
([Forms]![frmStudents]![CheckCriteria]=Yes) OR
(OtherInfo.HSGradYr=[forms]![frmStudents]![txtGradYear])
but I didn't get JUST the records where
OtherInfo.HSGradYr=[forms]![frmStudents]![txtGradYear] which makes sense.
Can anyone help me get what I need?
Thanks in advance,
Debbie | | | | re: Change query from textbox on form
DebbieG wrote:
[color=blue]
> I have a form based on this query:
>
>
> SELECT Students.LastSerDT, OtherInfo.Served, OtherInfo.HSGradYr,
> OtherInfo.ActivePart, OtherInfo.Served, Students.SSN, [LastNM] & ", " &
> [FirstNM] & " " & [MI] AS Name, Students.LastNM, Students.FirstNM,
> Students.MI, Students.DOB, Students.GenderCD, Students.EthnicityCD,
> Students.EligibilityCD, Students.UBInitiative, Students.NCESSchID,
> Students.ProjEntryDT, Students.ProjReEntDT, Students.LastSerDT,
> Students.Reason, Students.PartCD, Students.PartLV, Students.NeedCD,
> Students.AssessCD, Students.PSAT, Students.PLAN, Students.EnterGradeLV,
> Students.EndGradeLV, Students.EntryGPAScale, Students.CumGPAEntry,
> Students.EndGPAScale, Students.HSGPA1, Students.HSGPA2, Students.CollExamCD,
> OtherInfo.NCESSchNM, OtherInfo.MiddleNM, OtherInfo.CurrentGradeLV,
> OtherInfo.CurrentHSNM, Students.PicturePath
> FROM Students LEFT JOIN OtherInfo ON Students.SSN = OtherInfo.SSN
> WHERE (((Students.LastSerDT) Is Null)) OR (((OtherInfo.Served)=Yes)) OR
> ((([Forms]![frmStudents]![CheckCriteria])=Yes))
> ORDER BY Students.LastNM, Students.FirstNM;
>
> If [Forms]![frmStudents]![CheckCriteria]=No then it shows records WHERE
> Students.LastSerDT Is Null OR OtherInfo.Served=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_Click()
> 'if checkbox = yes then shows all students, else shows current/active
> Me.Requery
> Me.ComboStudent.Requery
> ShowName = ComboStudent.Column(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.LastSerDT Is Null OR OtherInfo.Served=Yes
>
> 2. WHERE [Forms]![frmStudents]![CheckCriteria]=Yes
>
> 3. WHERE OtherInfo.HSGradYr=[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.LastSerDT Is Null OR OtherInfo.Served=Yes) OR
> ([Forms]![frmStudents]![CheckCriteria]=Yes) OR
> (OtherInfo.HSGradYr=[forms]![frmStudents]![txtGradYear])
>
> but I didn't get JUST the records where
> OtherInfo.HSGradYr=[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.RowSourceString = Me.ComboboxName.RowSource
'remove the semi-colon if it exists since a ; terminates
'a SQL statement.
If right(Me.RowSourceString,1) = ";" Then
Me.RowSourceString = Left(Me.RowSourceString,Len(Me.RowSourceString)-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_AfterUpdate
Dim strWhere As String
'create the filter. Remember...quotes 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.RowSourceString & _
strWhere & " Order By Whatever"
End Sub | | | | re: Change query from textbox on form
"Salad" <oil@vinegar.com> wrote in message
news:VhWec.8198$A_4.4477@newsread1.news.pas.earthl ink.net...
DebbieG wrote:
[color=blue]
> I have a form based on this query:
>
>
> SELECT Students.LastSerDT, OtherInfo.Served, OtherInfo.HSGradYr,
> OtherInfo.ActivePart, OtherInfo.Served, Students.SSN, [LastNM] & ", " &
> [FirstNM] & " " & [MI] AS Name, Students.LastNM, Students.FirstNM,
> Students.MI, Students.DOB, Students.GenderCD, Students.EthnicityCD,
> Students.EligibilityCD, Students.UBInitiative, Students.NCESSchID,
> Students.ProjEntryDT, Students.ProjReEntDT, Students.LastSerDT,
> Students.Reason, Students.PartCD, Students.PartLV, Students.NeedCD,
> Students.AssessCD, Students.PSAT, Students.PLAN, Students.EnterGradeLV,
> Students.EndGradeLV, Students.EntryGPAScale, Students.CumGPAEntry,
> Students.EndGPAScale, Students.HSGPA1, Students.HSGPA2,[/color]
Students.CollExamCD,[color=blue]
> OtherInfo.NCESSchNM, OtherInfo.MiddleNM, OtherInfo.CurrentGradeLV,
> OtherInfo.CurrentHSNM, Students.PicturePath
> FROM Students LEFT JOIN OtherInfo ON Students.SSN = OtherInfo.SSN
> WHERE (((Students.LastSerDT) Is Null)) OR (((OtherInfo.Served)=Yes)) OR
> ((([Forms]![frmStudents]![CheckCriteria])=Yes))
> ORDER BY Students.LastNM, Students.FirstNM;
>
> If [Forms]![frmStudents]![CheckCriteria]=No then it shows records WHERE
> Students.LastSerDT Is Null OR OtherInfo.Served=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_Click()
> 'if checkbox = yes then shows all students, else shows current/active
> Me.Requery
> Me.ComboStudent.Requery
> ShowName = ComboStudent.Column(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.LastSerDT Is Null OR OtherInfo.Served=Yes
>
> 2. WHERE [Forms]![frmStudents]![CheckCriteria]=Yes
>
> 3. WHERE OtherInfo.HSGradYr=[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.LastSerDT Is Null OR OtherInfo.Served=Yes) OR
> ([Forms]![frmStudents]![CheckCriteria]=Yes) OR
> (OtherInfo.HSGradYr=[forms]![frmStudents]![txtGradYear])
>
> but I didn't get JUST the records where
> OtherInfo.HSGradYr=[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.RowSourceString = Me.ComboboxName.RowSource
'remove the semi-colon if it exists since a ; terminates
'a SQL statement.
If right(Me.RowSourceString,1) = ";" Then
Me.RowSourceString = Left(Me.RowSourceString,Len(Me.RowSourceString)-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_AfterUpdate
Dim strWhere As String
'create the filter. Remember...quotes 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.RowSourceString & _
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_Exit(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.GoToControl "txtGradYear"
Exit Sub
End If
Me.CheckCurrent = False 'based on qselStudents
Me.CheckCriteria = False 'based on qselStudents
Forms!frmStudents.RecordSource = "qselStudents2"
Dim strNewSource
strNewSource = "SELECT qselStudents2.SSN, " _
& "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.Column(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 | | | | re: Change query from textbox on form
DebbieG wrote:
[color=blue]
> "Salad" <oil@vinegar.com> wrote in message
> news:VhWec.8198$A_4.4477@newsread1.news.pas.earthl ink.net...
> DebbieG wrote:
>
>[color=green]
>>I have a form based on this query:
>>
>>
>>SELECT Students.LastSerDT, OtherInfo.Served, OtherInfo.HSGradYr,
>>OtherInfo.ActivePart, OtherInfo.Served, Students.SSN, [LastNM] & ", " &
>>[FirstNM] & " " & [MI] AS Name, Students.LastNM, Students.FirstNM,
>>Students.MI, Students.DOB, Students.GenderCD, Students.EthnicityCD,
>>Students.EligibilityCD, Students.UBInitiative, Students.NCESSchID,
>>Students.ProjEntryDT, Students.ProjReEntDT, Students.LastSerDT,
>>Students.Reason, Students.PartCD, Students.PartLV, Students.NeedCD,
>>Students.AssessCD, Students.PSAT, Students.PLAN, Students.EnterGradeLV,
>>Students.EndGradeLV, Students.EntryGPAScale, Students.CumGPAEntry,
>>Students.EndGPAScale, Students.HSGPA1, Students.HSGPA2,[/color]
>
> Students.CollExamCD,
>[color=green]
>>OtherInfo.NCESSchNM, OtherInfo.MiddleNM, OtherInfo.CurrentGradeLV,
>>OtherInfo.CurrentHSNM, Students.PicturePath
>>FROM Students LEFT JOIN OtherInfo ON Students.SSN = OtherInfo.SSN
>>WHERE (((Students.LastSerDT) Is Null)) OR (((OtherInfo.Served)=Yes)) OR
>>((([Forms]![frmStudents]![CheckCriteria])=Yes))
>>ORDER BY Students.LastNM, Students.FirstNM;
>>
>>If [Forms]![frmStudents]![CheckCriteria]=No then it shows records WHERE
>>Students.LastSerDT Is Null OR OtherInfo.Served=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_Click()
>> 'if checkbox = yes then shows all students, else shows current/active
>> Me.Requery
>> Me.ComboStudent.Requery
>> ShowName = ComboStudent.Column(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.LastSerDT Is Null OR OtherInfo.Served=Yes
>>
>>2. WHERE [Forms]![frmStudents]![CheckCriteria]=Yes
>>
>>3. WHERE OtherInfo.HSGradYr=[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.LastSerDT Is Null OR OtherInfo.Served=Yes) OR
>>([Forms]![frmStudents]![CheckCriteria]=Yes) OR
>>(OtherInfo.HSGradYr=[forms]![frmStudents]![txtGradYear])
>>
>>but I didn't get JUST the records where
>>OtherInfo.HSGradYr=[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.RowSourceString = Me.ComboboxName.RowSource
>
> 'remove the semi-colon if it exists since a ; terminates
> 'a SQL statement.
> If right(Me.RowSourceString,1) = ";" Then
> Me.RowSourceString = Left(Me.RowSourceString,Len(Me.RowSourceString)-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_AfterUpdate
> Dim strWhere As String
>
> 'create the filter. Remember...quotes 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.RowSourceString & _
> 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_Exit(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.GoToControl "txtGradYear"
> 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.RunCommand 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.SSN, _
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.CheckCriteria = False 'based on qselStudents
>
> Forms!frmStudents.RecordSource = "qselStudents2"
>
> Dim strNewSource
> strNewSource = "SELECT qselStudents2.SSN, " _
> & "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.Column(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] | | | | re: Change query from textbox on form
Thank you!
Debbie
"Salad" <oil@vinegar.com> wrote in message
news:Weafc.9706$A_4.2081@newsread1.news.pas.earthl ink.net...
DebbieG wrote:
[color=blue]
> "Salad" <oil@vinegar.com> wrote in message
> news:VhWec.8198$A_4.4477@newsread1.news.pas.earthl ink.net...
> DebbieG wrote:
>
>[color=green]
>>I have a form based on this query:
>>
>>
>>SELECT Students.LastSerDT, OtherInfo.Served, OtherInfo.HSGradYr,
>>OtherInfo.ActivePart, OtherInfo.Served, Students.SSN, [LastNM] & ", " &
>>[FirstNM] & " " & [MI] AS Name, Students.LastNM, Students.FirstNM,
>>Students.MI, Students.DOB, Students.GenderCD, Students.EthnicityCD,
>>Students.EligibilityCD, Students.UBInitiative, Students.NCESSchID,
>>Students.ProjEntryDT, Students.ProjReEntDT, Students.LastSerDT,
>>Students.Reason, Students.PartCD, Students.PartLV, Students.NeedCD,
>>Students.AssessCD, Students.PSAT, Students.PLAN, Students.EnterGradeLV,
>>Students.EndGradeLV, Students.EntryGPAScale, Students.CumGPAEntry,
>>Students.EndGPAScale, Students.HSGPA1, Students.HSGPA2,[/color]
>
> Students.CollExamCD,
>[color=green]
>>OtherInfo.NCESSchNM, OtherInfo.MiddleNM, OtherInfo.CurrentGradeLV,
>>OtherInfo.CurrentHSNM, Students.PicturePath
>>FROM Students LEFT JOIN OtherInfo ON Students.SSN = OtherInfo.SSN
>>WHERE (((Students.LastSerDT) Is Null)) OR (((OtherInfo.Served)=Yes)) OR
>>((([Forms]![frmStudents]![CheckCriteria])=Yes))
>>ORDER BY Students.LastNM, Students.FirstNM;
>>
>>If [Forms]![frmStudents]![CheckCriteria]=No then it shows records WHERE
>>Students.LastSerDT Is Null OR OtherInfo.Served=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_Click()
>> 'if checkbox = yes then shows all students, else shows current/active
>> Me.Requery
>> Me.ComboStudent.Requery
>> ShowName = ComboStudent.Column(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.LastSerDT Is Null OR OtherInfo.Served=Yes
>>
>>2. WHERE [Forms]![frmStudents]![CheckCriteria]=Yes
>>
>>3. WHERE OtherInfo.HSGradYr=[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.LastSerDT Is Null OR OtherInfo.Served=Yes) OR
>>([Forms]![frmStudents]![CheckCriteria]=Yes) OR
>>(OtherInfo.HSGradYr=[forms]![frmStudents]![txtGradYear])
>>
>>but I didn't get JUST the records where
>>OtherInfo.HSGradYr=[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.RowSourceString = Me.ComboboxName.RowSource
>
> 'remove the semi-colon if it exists since a ; terminates
> 'a SQL statement.
> If right(Me.RowSourceString,1) = ";" Then
> Me.RowSourceString = Left(Me.RowSourceString,Len(Me.RowSourceString)-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_AfterUpdate
> Dim strWhere As String
>
> 'create the filter. Remember...quotes 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.RowSourceString & _
> 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_Exit(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.GoToControl "txtGradYear"
> 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.RunCommand 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.SSN, _
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.CheckCriteria = False 'based on qselStudents
>
> Forms!frmStudents.RecordSource = "qselStudents2"
>
> Dim strNewSource
> strNewSource = "SELECT qselStudents2.SSN, " _
> & "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.Column(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] |  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|