T
Tarnia
I want to be able to use a combo box to set the criteria for a filter. My
code works, except if you search for the same name twice in a row (even after
showing all the records again) it changes the data values (from "jaimie" to
"anne" or some such). I don't understand why, so if anyone has any clue
(code below) I'd greatly appreciate it!
Sub Go_Click()
Dim Names, namefilter As String 'declare variables
Dim frm As Form
'lookup value for "name" in from viewlessonsbystudent3 and store as names
Names = DLookup("[Name]", "viewbystudent", "[name]='" &
Forms!viewlessonsbystudent3!Name & "'")
'build criteria for filtering for a given name and store as variable
namefilter
namefilter = BuildCriteria("Name", dbText, Names)
'open form
DoCmd.OpenForm "viewbystudent4"
'Return Form object variable set to "viewlessonsbystudent3".
Set frm = Forms!viewbystudent4
'filter records for that user selected (stored in names variable)
frm.filter = namefilter
FilterOn = True
'close form
DoCmd.Close acForm, "viewlessonsbystudent3"
End Sub
code works, except if you search for the same name twice in a row (even after
showing all the records again) it changes the data values (from "jaimie" to
"anne" or some such). I don't understand why, so if anyone has any clue
(code below) I'd greatly appreciate it!
Sub Go_Click()
Dim Names, namefilter As String 'declare variables
Dim frm As Form
'lookup value for "name" in from viewlessonsbystudent3 and store as names
Names = DLookup("[Name]", "viewbystudent", "[name]='" &
Forms!viewlessonsbystudent3!Name & "'")
'build criteria for filtering for a given name and store as variable
namefilter
namefilter = BuildCriteria("Name", dbText, Names)
'open form
DoCmd.OpenForm "viewbystudent4"
'Return Form object variable set to "viewlessonsbystudent3".
Set frm = Forms!viewbystudent4
'filter records for that user selected (stored in names variable)
frm.filter = namefilter
FilterOn = True
'close form
DoCmd.Close acForm, "viewlessonsbystudent3"
End Sub