473,748 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Nov 12 '05 #1
4 2609
DebbieG wrote:
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

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

Nov 12 '05 #2

"Salad" <oi*@vinegar.co m> wrote in message
news:Vh******** *********@newsr ead1.news.pas.e arthlink.net...
DebbieG wrote:
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

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

Nov 12 '05 #3
DebbieG wrote:
"Salad" <oi*@vinegar.co m> wrote in message
news:Vh******** *********@newsr ead1.news.pas.e arthlink.net...
DebbieG wrote:

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 ,
Students.CollEx amCD,
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


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.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


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

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


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?
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?

Thanks so much,
Debbie

Nov 12 '05 #4
Thank you!
Debbie

"Salad" <oi*@vinegar.co m> wrote in message
news:We******** *********@newsr ead1.news.pas.e arthlink.net...
DebbieG wrote:
"Salad" <oi*@vinegar.co m> wrote in message
news:Vh******** *********@newsr ead1.news.pas.e arthlink.net...
DebbieG wrote:

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 ,
Students.CollEx amCD,
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


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.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


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

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


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?
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?

Thanks so much,
Debbie

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
300
by: DebbieG | last post by:
I have a form based on this query: SELECT Students.LastSerDT, OtherInfo.Served, OtherInfo.HSGradYr, OtherInfo.ActivePart, OtherInfo.Served, Students.SSN, & ", " & & " " & 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,...
3
5013
by: Tom | last post by:
I am writing a Visual basic .Net database application. There are many forms that first let you select and look at a DB record and then when you click a "modify" button you are allowed to change data in the text boxes. Then an "update" button saves the data back to the database. What is the best way to change several properties on most of the textbox controls on the form when the "modify" button is clicked? (e.g. make them editible (and...
3
2229
by: Brad Rogers | last post by:
All, Being immersed in vb.net and trying CSharp after almost a year I forgot the differences. I like vb fixing the uppercase/lowercase names and seeming to be more flexible to code entry. But while trying to insert a text box to see when a method is used, and putting a counter to bump some variable? The textbox sits there unchanged. I put a breakpoint at the text write
3
3312
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when the field should only be showing one or the other (date or time). Even on the back end of the database where the column properties are, I have chosen the smallest date/time formats. When the aspx page runs, it shows the date and time (ie:in a...
2
5738
by: Mark Roughton | last post by:
I have a form where the users need to view records for various criteria, one of which is a date field on which they may wish to view all related data for the selected date, for all dates upto and icluding the selected date or all records on or after the selected date The user selects either "=", >=" or "<=" from a combo box and then a date from another combobox. The combination of thse two choices is then set in an unbound textbox so...
3
4559
by: DHarris | last post by:
I created a continuous form in Access2003 based on a query that users review customers and once reviewed clicks on a command button that executes an append query to update a table of the reviewed customer(s) data. The table includes the fields: customer_number, shipto_number . I also need to include the date reviewed and the user who performed the review in the append query. The command button is executing the query, however, the query appends...
8
3271
by: mlwerth | last post by:
Dear Access Group: This is the most basic and most embarrassing of questions, but I cannot find where to change the data type of a text field that I have in Access 2003 to a number field. I've searched high and low through help databases and on the internet. The directions say to : Open the table in Design view Click the Data Type column of the field you want to change, click the
1
2291
by: martin DH | last post by:
Hello, I have a unique situation, I believe. I have a form with unbound textboxes (frmEditReport) - most populate from a search query but one unbound textbox, txt_ReturnInfo, populates based on a selection the user chooses when logging in (code below). Basically, the user selects their office at login and the textbox will populate with the appropriate return mailing address when frmEditReport opens. I think this is most efficient since...
5
1984
by: agarwasa2008 | last post by:
Hi, I have a linked table called tbltest and some bounded forms (which add, update, delete records) that were created using that linked table. For some necessary reasons I had to create another linked table called tblComponents and then I bounded the original forms to this new table. I did change the control source: Description (Field name) RowSource Type: Table/Query (which remains the same)
0
8995
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9558
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9253
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6077
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.