Solved

allowedits in subform syntax

Posted on 2014-02-13
8
464 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

823 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