• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

allowedits in subform syntax

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
terpsichore
Asked:
terpsichore
  • 4
  • 3
2 Solutions
 
terpsichoreAuthor Commented:
CORRECTION - this error is only occurring THE FIRST TIME THE FORM LOADS. Any fixes? THANKS
0
 
Rey Obrero (Capricorn1)Commented:
where are you executing the code?
0
 
terpsichoreAuthor Commented:
in the current event of the (first) subform
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Rey Obrero (Capricorn1)Commented:
where is the subform "sfQuickView2" located ?
0
 
terpsichoreAuthor Commented:
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
 
Rey Obrero (Capricorn1)Commented:
<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
 
mbizupCommented:
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
 
terpsichoreAuthor Commented:
superb and insightful feedback.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now