Filter Command Button

  • Thread starter Thread starter Sol
  • Start date Start date
S

Sol

The wizard created the following code to filter a form
based on one linking field. I would like it to filter the
form based on (2) linked fields. The linked field below is
[Course Number], and I also need it filter by
[Semester/Year]. What do I need to add (and where) so it
will link both fields. Both fields are already in both
forms.

Thank you.

Sol


Private Sub View_Class_Click()
On Error GoTo Err_View_Class_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Classes Form"

stLinkCriteria = "[CourseNumber]=" & "'" & Me![Course
Number] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_View_Class_Click:
Exit Sub

Err_View_Class_Click:
MsgBox Err.Description
Resume Exit_View_Class_Click

End Sub
 
Using the same name for Controls and for Fields can lead to confusion and I
strongly suggest you change the names of the controls to include a prefix
"cbo" if they are Combo Boxes, or "txt" if they are Text. I suggest you also
do not use special characters, e.g., "/" in Field or Control names.

Assuming you are using Text Boxes, and assuming that your CourseNumber and
the SemesterYear Fields are both Text, try the following:

stLinkCriteria = "[CourseNumber]=" & "'" & Me![txtCourseNumber] & "' AND
[SemesterYear] =" & "'" & Me![txtSemesterYear] & "'"

Larry Linson
Microsoft Access MVP
 
Back
Top