473,320 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Error trying to AllowAdditions in a subform with no records

I needed to stop users from accidentally editing fields in several forms and subfoms. I'm not much of a programmer, so using code I found in various forums, I was able to turn off AllowEdits from On Current, then turn it back on when a button is clicked. Subforms are set to AllowEdits and AllowAdditions only when the parent form allows editing using On Enter.

However, if a subform doesn't have any records, I get Error 2474, "The expression you entered requires the control to be in the active window." The debugger stops on the following line: Screen.ActiveControl.Parent.AllowAdditions = True

Here's the code I'm using:
Expand|Select|Wrap|Line Numbers
  1. 'Called from clicking a button on the parent form
  2. Public Function Edit()
  3. Screen.ActiveForm.AllowEdits = Not Screen.ActiveForm.AllowEdits
  4. End Function
  5.  
  6. 'Called from On Current in the parent form
  7. Public Function Read()
  8. Screen.ActiveForm.AllowEdits = False
  9. End Function
  10.  
  11. 'Called from On Enter of the subform control
  12. Public Function AddEditSub()
  13. If Screen.ActiveForm.AllowEdits = True Then
  14.     Screen.ActiveControl.Parent.AllowAdditions = True
  15.     Screen.ActiveControl.Parent.AllowEdits = True
  16.     Exit Function
  17.         End If
  18. End Function
  19.  
  20. 'Called from On Enter of the subform control like previous when additions aren't needed
  21. Public Function EditSub()
  22. If Screen.ActiveForm.AllowEdits = True Then
  23.     Screen.ActiveControl.Parent.AllowEdits = True
  24.     Exit Function
  25.         End If
  26. End Function
  27.  
  28. 'Called from On Exit of the subform control
  29. Public Function ReadSub()
  30. Screen.ActiveControl.Parent.AllowAdditions = False
  31. Screen.ActiveControl.Parent.AllowEdits = False
  32. End Function
  33.  
What am I doing wrong and how can I work around it?

Thanks,
Frieda
Nov 24 '10 #1
1 2171
TheSmileyCoder
2,322 Expert Mod 2GB
And you Only get this error when the subform has no records?
Can you see the subform?
Ive had issues before where I was using allowadditions=false and allowedits=false, and when the subform had no records, the form would not display. And with the form not being displayed, neither were the Edit and New buttons on my subform.

Other then that, you could try to add a line saying:
On Error Resume Next
simply bypassing the error. You would have to test to see how that functions against your requirements.
Nov 25 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Deano | last post by:
Hi, I was just setting up a test system on a client's machine yesterday and as ever noticed a few problems. One that has thrown me is to do with the order of records in a subform (datasheet...
1
by: phaddock4 | last post by:
Being fairly inexperienced at Access 2000, i've been reading many posts here for the last several days, and testing myself to find the best approach to do the following in A2K: SET UP: I have...
1
by: Terri | last post by:
I'm summing subform records in a control on a main form. I have a control in the subform footer called TotalAmount with the control source =Sum(). On my mainform control I reference this control...
1
by: jmarr02s | last post by:
Is it possible to limit the number of Subform records using MS Access 2003? That is, my end users want the capability of entering up to 12 records on their subform. Is that possible? ...
3
by: paquer | last post by:
On my Main form I have a Command Button that opens a Subform in order to create a new Subform record. At this point I want the subform to show only the new record being created. Not all the...
5
by: Soccer5 | last post by:
Trying to Count records on a report that meet a certain criteria. Have a text box in the Report Footer that has the following in the Control Source: =Count(="S") This does not work. It...
0
by: jwbird | last post by:
I have a main form with multiple Subforms that are all displaying Datasheet information related to the Main form record. When I make changes/adds to the records(s) in the subform and tab to another...
3
by: DanSandbergUCONN | last post by:
I'm on a MacBook running mac osx 10.4.11, I have Xcode, gnu, and I'm using the terminal command: g++ -o helloworld helloworld.c I get the error: g++: error trying to exec 'cc1plus': execvp: No...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
2
by: matt753 | last post by:
I have a subform that holds a bunch of records for employees. Rather than manually scrolling through I want to be able to click on one and then the subform displays that record. I tried ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.