Solved

allowedits in subform syntax

Posted on 2014-02-13
8
466 Views
Last Modified: 2014-02-13
Dear experts  -
Hopefully simple...

I have 2 subforms on a form. In the current event on the one subform I want to control the allowedits on the other.

The following line is giving me the error "method or data member not found"

Forms!Main_Form!sfQuickView2.Form.AllowEdits = IIf(Nz(Forms!Main_Form!txtContact_ID, 0) <> 0, True, False)

sfQuickView2 is the control name of the other subform; the source object of that subform is also changed programmatically elsewhere (which is working fine).

Thanks!
0
Comment
Question by:terpsichore
  • 4
  • 3
8 Comments
 

Author Comment

by:terpsichore
ID: 39856023
CORRECTION - this error is only occurring THE FIRST TIME THE FORM LOADS. Any fixes? THANKS
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39856026
where are you executing the code?
0
 

Author Comment

by:terpsichore
ID: 39856047
in the current event of the (first) subform
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39856062
where is the subform "sfQuickView2" located ?
0
 

Author Comment

by:terpsichore
ID: 39856068
there is one main form (main_form), which has 2 subforms (on the same page): sfcontacts (whose Current event is firing the code above) and sfQuickView2
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 39856120
<THE FIRST TIME THE FORM LOADS>
the problem is,
you are calling the code in the current event of the subform "sfcontacts",
at this event, the Main form hasn't loaded yet, that is why the error  "method or data member not found" is triggered.

try calling the codes with an "If <....  >  Then "  condition
0
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 39856279
Curious why that code is not in the Main Form?  It seems like it is better suited for the main form.  You could place it in the Main Form's Current event (which would avoid the error on Loading issue) and in the After Update event of txtContact_ID (to respond to changes in that field).  The code would look like this in both of those events:

 Me.sfQuickView2.Form.AllowEdits = IIf(Nz(Me.txtContact_ID, 0) <> 0, True, False)

Open in new window



If you absolutely need that code in the subform current event, then you can also use error handling -- which sshould always be a part of your code anyway.  Since the error only occurs when the form opens, It is safe to simply exit the sub if that error is raised  (see my inline comments in the code):


Private Sub Form_Current()
     On Error Goto EH

    Forms!Main_Form!sfQuickView2.Form.AllowEdits = IIf(Nz(Forms!Main_Form!txtContact_ID, 0) <> 0, True, False)

     exit sub

EH:
    If Err.Number = 1234   then exit sub '<---*** Replace with the actual error code you are seeing
    msgbox "Error " & err.Number & ": " & err.description
End Sub]

Open in new window

0
 

Author Closing Comment

by:terpsichore
ID: 39856332
superb and insightful feedback.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question