I have found a thread [thread702-1209629] that seems to answer my question, however, that answer is not working for me. I would appreciate some assistance in identifying where I am going wrong, to which I'm sure it is to with referencing and have looked up many threads on this but I have still not been able to resolve my current problem.
Using Access 2003, I have a form "frmPatientBrowser" which includes an unbound text box "txtSurname" and a subform "ctrlPatientBrowser". The subform "sfrPatientBrowser" links to a table "tblPatients" which includes a field "surname" and is displayed as a datagrid. Fields displayed in the datagrid are (surname; firstname; address; suburb).
My plan is for the user to enter a Patients surname into the text box "txtSurname" and as they enter each character of the surname the subform (datagrid) is filtered using the text being typed with a "*" appended to the end of it. This should reduce the list of patients being displayed making it quicker for the user to select the appropriate patient.
My problem is that the subform is not being filtered. I have overcome my previous problems of the application crashing due to incorrect referencing.
The code I have tried is as follows:
I look forward to hearing where I have made my error(s).
Kind regards
Peter
Using Access 2003, I have a form "frmPatientBrowser" which includes an unbound text box "txtSurname" and a subform "ctrlPatientBrowser". The subform "sfrPatientBrowser" links to a table "tblPatients" which includes a field "surname" and is displayed as a datagrid. Fields displayed in the datagrid are (surname; firstname; address; suburb).
My plan is for the user to enter a Patients surname into the text box "txtSurname" and as they enter each character of the surname the subform (datagrid) is filtered using the text being typed with a "*" appended to the end of it. This should reduce the list of patients being displayed making it quicker for the user to select the appropriate patient.
My problem is that the subform is not being filtered. I have overcome my previous problems of the application crashing due to incorrect referencing.
The code I have tried is as follows:
Code:
Option Compare Database
Option Explicit
Private Sub txtSurname_Change()
Dim strFilterValue As String
Dim strPatient As String
strFilterValue = txtSurname.Text
MsgBox ("before " & strFilterValue) 'just checking the progress - all OK so far!
'The following line of code (commented out) does not work yet the one after does
'Happy to be advised why??
'strPatient = Me.Parent![ctrlPatientBrowser].Form![txtSurname].Text (does NOT work)
strPatient = Forms![frmpatientBrowser]![ctrlPatientBrowser].Form![txtSurname].Text 'WORKS
MsgBox ("surname = " & strPatient) ' just checking my referencing - all OK so far
'The following line of code from thread702-1209629 is used as a guide:
'[Forms]![FrmBrowser]![FrmBrowser subform].Form.Filter = "Dealership='" & Criteria & "'"
'PROBLEM - I believe the following line of code is my issue and have used the filter code
'from another example - see below:
'rsSubMain.Filter = "LName LIKE '" & txtNameFilter.Text & "*'"
'Me.Filter = "Country = 'USA'"
Forms![frmpatientBrowser]![ctrlPatientBrowser].Form.Filter = "surname LIKE '" & strFilterValue & "*'"
End Sub
I look forward to hearing where I have made my error(s).
Kind regards
Peter