Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

allowedits in subform syntax

Posted on 2014-02-13
8
Medium Priority
?
476 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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 1000 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 1000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

886 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