I have some code that allows users to filter a list of street address. It works fine except for when a user makes changes to a record then goes to search for a street. I get error number 3219 "Operation not allowed in this context". And the program stops on the Close method (see code below. Is there a way around this problem?
Thank you in advance for any assistance.
Private Sub txtStrFilter_Change()
'Limits the accounts displayed in dgdMain to those which have street names that begin with _
'the letters keyed in by the user
'For SQL query use to open rsSubMain
Dim strSQL As String
strSQL = "SELECT AcctNum, FName, LName, HouseNum, Fraction, Street, AptNum, City, State, ZipPlus, DoNotMail, UseAltAddress, SendWelcome " & _
"FROM SubMain " & _
"WHERE Street LIKE '" & txtStrFilter.Text & "%' " & _
"ORDER BY Street, HouseNum, Fraction, AptNum, LName, FName"
'Closes then immediatly opens rsSubMain. Each time rsSubMain is opened it will _
'only contain the records where the street name starts with the letters keyed in by the user
With rsSubMain
.Close
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open strSQL, conSubscription, , , adCmdText
End With
'Sets dgdMain's datasource equal to the newly reopened recordset
Set dgdMain.DataSource = rsSubMain
'Runs the SetupDataGrids subprocedure to ensure the date in dgdMain in displayed in _
'the proper format
SetupDataGrids
'Run the BindData Subprocedure to ensure the text boxes display the correct data
BindData
End Sub
Thank you in advance for any assistance.
Private Sub txtStrFilter_Change()
'Limits the accounts displayed in dgdMain to those which have street names that begin with _
'the letters keyed in by the user
'For SQL query use to open rsSubMain
Dim strSQL As String
strSQL = "SELECT AcctNum, FName, LName, HouseNum, Fraction, Street, AptNum, City, State, ZipPlus, DoNotMail, UseAltAddress, SendWelcome " & _
"FROM SubMain " & _
"WHERE Street LIKE '" & txtStrFilter.Text & "%' " & _
"ORDER BY Street, HouseNum, Fraction, AptNum, LName, FName"
'Closes then immediatly opens rsSubMain. Each time rsSubMain is opened it will _
'only contain the records where the street name starts with the letters keyed in by the user
With rsSubMain
.Close
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open strSQL, conSubscription, , , adCmdText
End With
'Sets dgdMain's datasource equal to the newly reopened recordset
Set dgdMain.DataSource = rsSubMain
'Runs the SetupDataGrids subprocedure to ensure the date in dgdMain in displayed in _
'the proper format
SetupDataGrids
'Run the BindData Subprocedure to ensure the text boxes display the correct data
BindData
End Sub