Hello all.
Please help me with this error, I have no clue why it is happening, maybe you do have. I know this is a bit long, I've made it the simpliest and clearest I could.
I have a code that is designed to go to a specific record in Forms!frmCustomersByCity!subfrmCustomers.Form!Cust omer_Id with a specific city filter Forms!frmCustomersByCity!subfrmCity.Form!City_Id that are in main form Forms!frmCustomersByCity, using bound textbox and unbound combo box values Forms!frmDistribution!cboCustomer_Id.Value, Forms!frmDistribution!cboCity_Id.Value of the form Forms!frmDistribution. I can't use DoCmd.GoToRecord method since it's the record to be gone to is on a subform.
Here's is it again:
open from the form: Forms!frmDistribution,
Values: Forms!frmDistribution!cboCustomer_Id.Value, Forms!frmDistribution!cboCityList.Value
the form to be opened: Forms!frmCustomersByCity
goto: Forms!frmCustomersByCity!subfrmCustomers.Form!Cust omer_Id
filter by: Forms!frmCustomersByCity!subfrmCity.Form!City_Id
the code I'm using from frmDistribution is: - Private Sub OpenfrmCustomersByCity_Click()
-
Dim strPageToOpen As String
-
Dim stLinkCriteria As String
-
strPageToOpen = "gotorecord"
-
DoCmd.OpenForm "frmCustomersByCity", , , stLinkCriteria, , , strPageToOpen
-
End Sub
the code I'm using in the form to be opened is: - Private Sub Form_Load()
-
Select Case OpenArgs
-
Case "gotorecord"
-
Dim rs As DAO.Recordset
-
Dim frm As Form
-
Set frm = Forms!frmCustomersByCity!subfrmCustomers.Form
-
Set rs = frm.RecordsetClone
-
-
'assign and activate filter city value
-
Me.subfrmCity.Form.CityList.Value = _
-
Forms!frmDistribution!CityList.Value
-
Me.subfrmCustomerst.Form.FilterOn = True
-
-
'assign and goto customer record
-
Me.subfrmCustomerst.Form.Filter = "subfrmCustomerst.ID_City = " _
-
& "Forms!frmCustomersByCity!subfrmCity.Form!CityList.Value"
-
-
-
- 'here I get RunTime Error 3420: Object Invalid or no longer set
-
rs.FindFirst "[Customer_Id] = " & Forms!frmDistribution!cmoCustomer_Id
-
-
-
If rs.NoMatch Then
-
MsgBox "can't find record"
-
Else
-
'Display the found record in the form.
-
frm.Bookmark = rs.Bookmark
-
End If
-
Set rs = Nothing
-
Set frm = Nothing
-
End Select
-
End Sub
Does anyone can tell why it is happening?
Thanks a bunch, Michael.
18 3070
Hello all.
Please help me with this error, I have no clue why it is happening, maybe you do have. I know this is a bit long, I've made it the simplest and clearest I could.
I have a code that is designed to go to a specific record in Forms!frmCustomersByCity!subfrmCustomers.Form!Cust omer_Id with a specific city filter Forms!frmCustomersByCity!subfrmCity.Form!City_Id that are in main form Forms!frmCustomersByCity, using bound textbox and unbound combo box values Forms!filmdistribution!cboCustomer_Id.Value, Forms!filmdistribution!society_Id.Value of the form Forms!filmdistribution. I can't use DoCmd.GoToRecord method since it's the record to be gone to is on a subform.
Here's is it again:
open from the form: Forms!filmdistribution,
Values: Forms!filmdistribution!cboCustomer_Id.Value, Forms!filmdistribution!cboCityList.Value
the form to be opened: Forms!frmCustomersByCity
goto: Forms!frmCustomersByCity!subfrmCustomers.Form!Cust omer_Id
filter by: Forms!frmCustomersByCity!subfrmCity.Form!City_Id
the code I'm using from filmdistribution is: - Private Sub OpenfrmCustomersByCity_Click()
-
Dim strPageToOpen As String
-
Dim stLinkCriteria As String
-
strPageToOpen = "gotorecord"
-
DoCmd.OpenForm "frmCustomersByCity", , , stLinkCriteria, , , strPageToOpen
-
End Sub
the code I'm using in the form to be opened is: - Private Sub Form_Load()
-
Select Case OpenArgs
-
Case "gotorecord"
-
Dim rs As DAO.Recordset
-
Dim frm As Form
-
Set frm = Forms!frmCustomersByCity!subfrmCustomers.Form
-
Set rs = frm.RecordsetClone
-
-
'assign and activate filter city value
-
Me.subfrmCity.Form.CityList.Value = _
-
Forms!filmdistribution!CityList.Value
-
Me.subfrmCustomerst.Form.FilterOn = True
-
-
'assign and goto customer record
-
Me.subfrmCustomerst.Form.Filter = "subfrmCustomerst.ID_City = " _
-
& "Forms!frmCustomersByCity!subfrmCity.Form!CityList.Value"
-
-
-
- 'here I get RunTime Error 3420: Object Invalid or no longer set
-
rs.FindFirst "[Customer_Id] = " & Forms!filmdistribution!cmpcustomer_Id
-
-
-
If rs.NoMatch Then
-
MsgBox "can't find record"
-
Else
-
'Display the found record in the form.
-
frm.Bookmark = rs.Bookmark
-
End If
-
Set rs = Nothing
-
Set frm = Nothing
-
End Select
-
End Sub
Does anyone can tell why it is happening?
Thanks a bunch, Michael.
It looks like 1 of 2 possibilities
__1 Is your Sub-Form subfrmCustomers or subfrmCustomerst? Both are specifically referenced in the code. If this is just a typo then:
__2 Explanation follows: - Dim rs As DAO.Recordset
-
Dim frm As Form
'The Object Variable rs is pointing to a copy of the Recordset for subfrmCustomers (RecordsetClone) - Set frm = Forms!frmCustomersByCity!subfrmCustomers.Form
- Set rs = frm.RecordsetClone
Once you apply a Filter to it as in: - Me.subfrmCustomerst.Form.FilterOn = True 'typo?
-
rs will no longer be valid. The Object Variable (rs) pointed to the underlying Recordset of subfrmCustomers 'before' the Filter was applied.! - Me.subfrmCustomerst.Form.FilterOn = True
When you now try to initiate a FindFirst, what does rs point to? - rs.FindFirst "[Customer_Id] = " & Forms!filmdistribution!cmpcustomer_Id
NOTE: I think I'm on the right track with this, if not I apologize for the endless gibbrish!
It looks like 1 of 2 possibilities
__1 Is your Sub-Form subfrmCustomers or subfrmCustomerst? Both are specifically referenced in the code. If this is just a typo then:
(It was a typo, I simplified names here.)
__2 Explanation follows: - Dim rs As DAO.Recordset
-
Dim frm As Form
'The Object Variable rs is pointing to a copy of the Recordset for subfrmCustomers (RecordsetClone) - Set frm = Forms!frmCustomersByCity!subfrmCustomers.Form
- Set rs = frm.RecordsetClone
Once you apply a Filter to it as in: - Me.subfrmCustomerst.Form.FilterOn = True 'typo?
-
rs will no longer be valid. The Object Variable (rs) pointed to the underlying Recordset of subfrmCustomers 'before' the Filter was applied.! - Me.subfrmCustomerst.Form.FilterOn = True
First, Thanks for looking into this. How cool, you are absolutely right, that is the problem.
Now I've put all that is to do with form filtering before the recordset code and recordset dimensioning, and it works fine.
Can you explain why filteron makes rs no longer valid?
(It was a typo, I simplified names here.)
First, Thanks for looking into this. How cool, you are absolutely right, that is the problem.
Now I've put all that is to do with form filtering before the recordset code and recordset dimensioning, and it works fine.
Can you explain why filteron makes rs no longer valid?
Note: If you close a form or if you change the form's RecordSource property, the Recordset object is no longer valid. If you subsequently refer to the Recordset object or to previously saved bookmarks in the form or the Recordset object, an error will occur. By applying a Filter, you are, in essence changing the Form's RecordSource property which in turn would apply to a Recordset Clone.
Note: If you close a form or if you change the form's RecordSource property, the Recordset object is no longer valid. If you subsequently refer to the Recordset object or to previously saved bookmarks in the form or the Recordset object, an error will occur. By applying a Filter, you are, in essence changing the Form's RecordSource property which in turn would apply to a Recordset Clone.
Much thanks for your reply.
I hope I could ask here why another code doesn't work for me, and how is it related to what have been explained here, as it is something of this subject.
I have a procedure that changes form's RecordSource to query another query, of exactly the same table, fields and metadata, and I want to keep the same filter to be applied as with the previous RecordSource: - Private Sub cmdView_Click()
-
dim strFilter as String
-
-
strFilter = Me.Form.Filter
-
-
Me.Form.RecordSource = "Distribution2"
-
Me.Form.Requery
-
Me.Form.Filter = strFilter
-
Me.Form.FilterOn = True
-
End Sub
After the procedure runs, the filter isn't applied, and in fact, the form show's no records at all.
The funny thing is the filter does apply if I add it On Load procedure of the form:
Me.Form.Filter = "filter"
Me.Form.FilterOn = True
Why is that, and how can I work around it?
Much thanks.
Much thanks for your reply.
I hope I could ask here why another code doesn't work for me, and how is it related to what have been explained here, as it is something of this subject.
I have a procedure that changes form's RecordSource to query another query, of exactly the same table, fields and metadata, and I want to keep the same filter to be applied as with the previous RecordSource: - Private Sub cmdView_Click()
-
dim strFilter as String
-
-
strFilter = Me.Form.Filter
-
-
Me.Form.RecordSource = "Distribution2"
-
Me.Form.Requery
-
Me.Form.Filter = strFilter
-
Me.Form.FilterOn = True
-
End Sub
After the procedure runs, the filter isn't applied, and in fact, the form show's no records at all.
The funny thing is the filter does apply if I add it On Load procedure of the form:
Me.Form.Filter = "filter"
Me.Form.FilterOn = True
Why is that, and how can I work around it?
Much thanks.
At a guess I would say it is because you are trying to change the recordsource and filter of the query while the form is open. You can't do this. However, it will work in the On Load event because the form is not yet open. You will have to close the form and reopen it with the code in the on load event for it to work. You are not changing the filter so I would suggest setting up a small unbound form with a dropdown list of the Record souces and a command button to open the form. As long as the previous form remains open this should work for you. -
Private Sub Form_Load()
-
-
Me.RecordSource = Forms!Form1Name!ComboBoxName
-
Me.Requery
-
-
End Sub
-
At a guess I would say it is because you are trying to change the recordsource and filter of the query while the form is open. You can't do this. However, it will work in the On Load event because the form is not yet open. You will have to close the form and reopen it with the code in the on load event for it to work.
But wait, If I change the RecordSource by one command button, and then apply filter by another command button, the filter does work...
Much thanks for your reply.
I hope I could ask here why another code doesn't work for me, and how is it related to what have been explained here, as it is something of this subject.
I have a procedure that changes form's RecordSource to query another query, of exactly the same table, fields and metadata, and I want to keep the same filter to be applied as with the previous RecordSource: - Private Sub cmdView_Click()
-
dim strFilter as String
-
-
strFilter = Me.Form.Filter
-
-
Me.Form.RecordSource = "Distribution2"
-
Me.Form.Requery
-
Me.Form.Filter = strFilter
-
Me.Form.FilterOn = True
-
End Sub
After the procedure runs, the filter isn't applied, and in fact, the form show's no records at all.
The funny thing is the filter does apply if I add it On Load procedure of the form:
Me.Form.Filter = "filter"
Me.Form.FilterOn = True
Why is that, and how can I work around it?
Much thanks.
If you explicitly assign the Filter, it will work: - strFilter = "[LastName]='" & "Dezii" & "'"
But wait, If I change the RecordSource by one command button, and then apply filter by another command button, the filter does work...
Michael you said the filter didn't change so why do you need to apply it using the command button. If you really do for some reason we can add it to the code on the other button but if it's preset on the form it shouldn't change.
Mary
pls could you give me list of books i can read to understand how to develope Visual basic Application codes that could populate oracle database when appended to excel spreadsheet
pls could you give me list of books i can read to understand how to develope Visual basic Application codes that could populate oracle database when appended to excel spreadsheet
Please do not hijack another posters thread. Start a discussion to open your own question.
ADMIN
If you explicitly assign the Filter, it will work: - strFilter = "[LastName]='" & "Dezii" & "'"
I've tried even adding it without the variable medium, and it still didn't work.
Michael you said the filter didn't change so why do you need to apply it using the command button. If you really do for some reason we can add it to the code on the other button but if it's preset on the form it shouldn't change.
The command I have runs a procedure that changes forms .RecordSource and then applies a filter, but that results in an empty form. However, if the filter is applied later via another command, it does work properly.
I've tried even adding it without the variable medium, and it still didn't work.
The command I have runs a procedure that changes forms .RecordSource and then applies a filter, but that results in an empty form. However, if the filter is applied later via another command, it does work properly.
But if the filter is set in the filter property of the form it won't need to be applied in code.
But if the filter is set in the filter property of the form it won't need to be applied in code.
But how can I determine what filter is it when I change the .RecordSource? It could be more than one filter.
- Me.Form.Filter = "[LastName]='" & "Dezii" & "'"
-
Me.Form.FilterOn = True
I added this to the code, and now at least it works, and not hides all the records
It works only if the filter is assigned explicitly, as Adezii suggested, but I can't use this solution, because the form has a possibility of changing the filter during the work.
- Me.Form.Filter = "[LastName]='" & "Dezii" & "'"
-
Me.Form.FilterOn = True
I added this to the code, and now at least it works, and not hides all the records
It works only if the filter is assigned explicitly, as Adezii suggested, but I can't use this solution, because the form has a possibility of changing the filter during the work.
Michael,
This is new information as in your first post you said the filter didn't change.
If the filter is changing you will have to apply it each time. How and when is this change being triggered.
Mary
Michael,
This is new information as in your first post you said the filter didn't change.
If the filter is changing you will have to apply it each time. How and when is this change being triggered.
Mary
Thanks for answering. I appologize for not making this clear.
The filter can be changed at any time, but when the form switches to another RecordSource, the filter should remain the same, as it was in its latest of the preivous RecordSource, just before the change, that's why I've coded: -
strFilter = Me.Form.Filter
-
-
Me.Form.RecordSource = "Distribution2"
-
Me.Form.Requery
-
Me.Form.Filter = strFilter
-
Me.Form.FilterOn = True
Michael.
Micael
Have a look at NeoPa's tutorial on this and see if there is anything there that can help out. Example Filtering on a Form
Mary
I haven't found there anything on the problem of applying a filter again after changing the RecordSouce of a form.
I wonder if it is possible to do so at all, and if not, what is the exact cause that prevents it. It seems to me like although maybe not so common but a relevant thing to preform. It is silly that it doesn't work via coding, but does work if I create a special button that sets the filter again, and press on it after changing the RecordSource.
Regards.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: astro |
last post by:
Anyone have suggestions on where to troubleshoot this error?
Background:
-Access 2k v. 9.0.6926 sp3
- front and backend on production server (wiindows 2k)
-accessed via Citrix
-front-end is...
|
by: Michael |
last post by:
Hi,
Any one know the problem of the following error:
Thanks,
m
Failed to load viewstate. The control tree into which
viewstate is being loaded must match the control tree
that was used to...
|
by: ST |
last post by:
Hi,
I keep getting the parser error, and I have no idea why. I've tried a
number of things including:
1)building/rebuilding about 100x
2)making sure all dll's are in the bin folder in the root...
|
by: Patrick |
last post by:
I understand it is built in behaviour that if an ASP.NET's web.config is set
to:
<customErrors
mode="RemoteOnly"
/>
then I only get a detailed error message on screen when the ASP.NET...
|
by: Tim |
last post by:
Greetings!
I have a UserControl. On this UserControl is a Panel and a
RadioButtonList. The Panel's Visible property is set to false by
default. When the user selects a particular...
|
by: Kasp |
last post by:
When I try and save out a recordset from an ASP page as XML I get the
following error (the code is below) - I have ADO 2.8 installed and this
is running on win XP sp2 :
...
|
by: HKSHK |
last post by:
This list compares the error codes used in VB.NET 2003 with those used
in VB6.
Error Codes:
============
3: This Error number is obsolete and no longer used. (Formerly:
Return without GoSub)...
|
by: contractsup |
last post by:
Environment:
$ uname -a
AIX <withheld2 5 000100614C00
$ db2level
DB21085I Instance "<withheld>" uses "32" bits and DB2 code release
"SQL08024"
with level identifier "03050106"....
|
by: Kosmos |
last post by:
Hey ya'll...I can't seem to figure out why I'm getting this error message, but it all started when I added the new line of code with the recSet5.AddNew --- when I ran the first line, the logic worked...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |