Malcolmneill
Registered User.
- Local time
- Today, 08:53
- Joined
- May 7, 2011
- Messages
- 17
I have viewed a lot of posts regarding problems in this area but can't seem to find the answer. I am not a VBA/Access beginner, but am still at an early stage.
My problem description:
I have a form with a subform which allows for the input of a number of items. Think of a reference sheet with related items. Each sheet can have multiple items from 1 to "n", but in practice less than 10. On saving the Form I need to determine the number of items attached to this sheet and then store it. So on exiting/saving the data I execute code to count the number of records and store the result.
I have attached a word document showing the error and the statement, BUT I have used this format elsewhere several times and it's fine. The issue seems to be that it doesn't like a temporary Variable, but why? The query simply selects all records attached to a specified sheet, the Sheet Number is in a "TempVar". If I execute the query with a DoCmd it's fine but doing the same thing with the openrecordset fails.
I tried using a variable defined in the sub routine but no change and you can see in the code various options of the Set statement. If I try the last one (labelled no 5) with a valid sheet no "M244" it does not fail but does not select anything either! If I use no **3 this is OK, but another query which has fixed criteria for the selection.
This has got me baffled so please any suggestions? If there's a better way then please advise.
Thanks
Malcolm
My problem description:
I have a form with a subform which allows for the input of a number of items. Think of a reference sheet with related items. Each sheet can have multiple items from 1 to "n", but in practice less than 10. On saving the Form I need to determine the number of items attached to this sheet and then store it. So on exiting/saving the data I execute code to count the number of records and store the result.
I have attached a word document showing the error and the statement, BUT I have used this format elsewhere several times and it's fine. The issue seems to be that it doesn't like a temporary Variable, but why? The query simply selects all records attached to a specified sheet, the Sheet Number is in a "TempVar". If I execute the query with a DoCmd it's fine but doing the same thing with the openrecordset fails.
I tried using a variable defined in the sub routine but no change and you can see in the code various options of the Set statement. If I try the last one (labelled no 5) with a valid sheet no "M244" it does not fail but does not select anything either! If I use no **3 this is OK, but another query which has fixed criteria for the selection.
This has got me baffled so please any suggestions? If there's a better way then please advise.
Thanks
Malcolm
Attachments
Last edited: