473,395 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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

Nov 12 '05 #2

"Salad" <oi*@vinegar.com> wrote in message
news:Vh*****************@newsread1.news.pas.earthl ink.net...
DebbieG wrote:
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

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

Nov 12 '05 #3
DebbieG wrote:
"Salad" <oi*@vinegar.com> wrote in message
news:Vh*****************@newsread1.news.pas.earthl ink.net...
DebbieG wrote:

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


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

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


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?
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.com> wrote in message
news:We*****************@newsread1.news.pas.earthl ink.net...
DebbieG wrote:
"Salad" <oi*@vinegar.com> wrote in message
news:Vh*****************@newsread1.news.pas.earthl ink.net...
DebbieG wrote:

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


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

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


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?
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
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,...
3
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...
3
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. ...
3
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...
2
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...
3
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...
8
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...
1
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...
5
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.