?
Solved

Enable/Disable fields on a tabbed sub-form.

Posted on 2012-08-20
17
Medium Priority
?
545 Views
Last Modified: 2012-08-27
The below code is in place to indicate whether a report is required and then to select the type:

Private sub chk_Report_Required_Click

    if me.chk_Report_Required = False then
        me.og_Report_Type = Null
        me.og_Report_Type.Enabled = False
    else    
        me.og_Report_Type.Enabled = True
    end if

End Sub

The og_Report_Type has three choices 1, 2, or 3

If Option 1 is selected in the og_Report_Type, I want to enable a date field on a tabbed sub-form (ISSIHSubmittedDate)

If Option 2 is selected in the og_Report_Type, I want to enable a differnt date field on a tabbed sub-form (FollowupReportDate)

If Option 3 is selected in the og_Report_Type, I want to enable a different date field on a tabbed sub-form (FinalReportDate)

If the chk_Report_Required is No, I want the three date fields disabled

Note: I know my naming conventions are screwed up but it would take a significant amount of work to re-do what's done.
0
Comment
Question by:Joe
  • 7
  • 5
  • 3
15 Comments
 

Author Comment

by:Joe
ID: 38313271
The brakketted info above is the field names - not the tab names. The tab is called Incident Details.
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38314322
Add an After Update event to og_Report_Type:
Private Sub og_Report_Type_AfterUpdate()
    With Me.NameOfSubform.Form
        !ISSIHSubmittedDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 1
        !FollowupReportDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 2
        !FinalReportDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 3
    End With
End Sub

Open in new window

Then at the end of your chk_Report_Required_Click routine, add this:
Call og_Report_Type_AfterUpdate
0
 

Author Comment

by:Joe
ID: 38316808
I was mistaken in telling you that the fields were on a tabbed "sub-form". They are on a tab called Incident_Details but not in an actual sub_form. How does that change the code?
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 

Author Comment

by:Joe
ID: 38317302
I modified the code to read:

Private Sub og_Report_Type_AfterUpdate()
        !ISSIHSubmittedDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 1
        !FollowupReportDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 2
        !FinalReportDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 3
End Sub

On selelction of one of the Report Types, I receive an error message that states:

Compile error:
Invalid or unqualified reference (chk_Report_Required highlighted)
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 1400 total points
ID: 38318967
You need to use the Me keyword:
Private Sub og_Report_Type_AfterUpdate()
        Me.ISSIHSubmittedDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 1
        Me.FollowupReportDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 2
        Me.FinalReportDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 3
End Sub

Open in new window

0
 

Author Comment

by:Joe
ID: 38320820
Thank You very much. This works great for my new records. How do I get the existing records to enable or disable the fields as necessary?
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38320891
Move the code I have you to the form's On Current event.
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38320900
I meant the code I gave you.
0
 
LVL 14

Expert Comment

by:pteranodon72
ID: 38321688
I would suggest that you move IrogSinta's code into a separate sub, let's call it Sub EnableDisable. Then you would put:

EnableDisable

in the following events:
Form_Current (after record navigation)
chk_Report_Required_AfterUpdate (change to this field needs update)
og_Report_Type_AfterUpdate (change to this field needs update)

This means you only have one copy of the EnableDisable code, but it is called from all places where the results could change. If you add another control to evaluate in EnableDisable, you add a call to EnableDisable to that control's AfterUpdate .

HTH,
pT72
0
 

Author Comment

by:Joe
ID: 38321965
Sorry for sounding completely foolish but what do you mean when you say move the code into a seperate sub?
0
 
LVL 14

Assisted Solution

by:pteranodon72
pteranodon72 earned 600 total points
ID: 38322199
No, that's fine -- how would you know if you haven't done it before?

Sub is short for subroutine.
If you scroll down to the bottom of the code window behind your form and type Sub EnableDisable, the editor will automatically add parentheses and the line End Sub.
This is now a subroutine that runs whenever its name (EnableDisable) appears (is called) in the other code. Put IrogSinta's three lines inside so that the end result looks like:
Sub EnableDisable()
        Me.ISSIHSubmittedDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 1
        Me.FollowupReportDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 2
        Me.FinalReportDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 3
End Sub

Open in new window

Now, you'll include a call to that subroutine inside Form_Current and each event that might make a difference:
Private Sub Form_Current()
EnableDisable
End Sub


Private Sub og_Report_Type_AfterUpdate()
        EnableDisable
End Sub

Private Sub chk_Report_Required_AfterUpdate ()
        EnableDisable
End Sub

Open in new window

Remember to replace the current 5 line definition for:
Private Sub og_Report_Type_AfterUpdate()
with the new one -- you can't leave both in!

Hope this helps,
pT72



Currently , the three lines of code are inside the
Private Sub og_Report_Type_AfterUpdate()
        Me.ISSIHSubmittedDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 1
        Me.FollowupReportDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 2
        Me.FinalReportDate.Enabled = Me.chk_Report_Required And Me.og_Report_Type = 3
End Sub

Open in new window

0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38323550
I'm glad pteranodon72 was able to help you out with an excellent explanation since I couldn't get back to you.  However, since you are also availing of the code I gave you, it would have been nice if you had split the points between us.
0
 
LVL 14

Expert Comment

by:pteranodon72
ID: 38324734
I totally agree -- IrogSinta deserves at least half the points for ID: 38318967 - the code that got it working.

pT72
0
 

Author Comment

by:Joe
ID: 38325208
My sincerest apologies. I wasn't paying attention. How do I correct this ?
0
 

Author Comment

by:Joe
ID: 38325462
I was mistaken in my point allotment and would like to re-allocate if possible. I would like to give IrogSinta 350 points for http:#a38318967  and pteranodon72 150 points for http:#a38322199.

I apologize for my oversight.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

840 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