Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Msg box or greying out fields depending on list box selection. 1

Status
Not open for further replies.

Triacona

Technical User
Jun 11, 2009
462
GB
Dear all,

I would really appreciate some help on this, thanks [smile]

I have a form - (MainScreen)

This form has several tabs, each relating to a specific selection of tables.

On one of my tabs - (Residential Premises)
I have a list box which lists reports
Code:
"RP Report Via Open Cases";"RP Report on Type for Open Cases";"RP Report Open Cases Via Officer";"RP Report Case Via Officer";"RP Report Via Officer and Action Date";"RP Hazards Sorted via Rating";"RP Hazards Sorted Via Officer"
Then on the right hand side of this list there are fields to be filled in:
Screen Name : Form Name
Start Date : RpStartDate (Date chooser ActiveX)
End Date : RpEndDate (Date chooser ActiveX)
Officer : RpCmbOfficer (Combo box)
Type : RpCmbTyp (Combo Box)

I would preferably like, when the user clicks on a specific report name in my left hand side list, for certain fields on the right to grey out (Meaning they cannot be used)

Any help would really be appreciated, I don't know where to start really.
Do I code each field?
Is there a nested If statement, I need to formulate?[ponder]

Again your help would really be appreciated. [smile]

Many thanks,

Kind regards

Triacona
 
You can do this on the Click of the List, a simple example (to illustrate the idea) might be:
Code:
Private Sub lstReports_Click()

Select Case lstReports.ItemData(lstReports.ListIndex)

Case "RP Hazards Sorted via Rating"
    RpStartDate.Enabled = False
    '... other controls Enabled state
Case "RP Report Via Open Cases"
    RpStartDate.Enabled = True
    '... other controls Enabled state
End Select
End Sub
Hope this helps

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Chief answer mate!!! Thank you!! [bigsmile]
It works brilliantly!
Code:
Private Sub ListRP_AfterUpdate()

Select Case ListRP.ItemData(ListRP.ListIndex)

Case "RP Report Via Open Cases"
    RpStartDate.Enabled = False
    RpEndDate.Enabled = False
    '... other controls Enabled state
Case "RP Report Case Via Officer", "RP Report Via Officer and Action Date", "RP Hazards Sorted via Rating", "RP Hazards Sorted Via Officer"
    RpStartDate.Enabled = True
    RpEndDate.Enabled = True
    '... other controls Enabled state
End Select

End Sub

Thanks again [2thumbsup]
They deactivate based on selection brilliantly.
Is there any way to grey them out as well?[ponder]

Kind regards

Triacona
 
Dear Andy,

Thanks again for your help [smile]
I have figured out a way to "grey out" the unwanted fields.
I have made them non-visable when the specific list item is selected.
Code:
Private Sub ListRP_AfterUpdate()

Select Case ListRP.ItemData(ListRP.ListIndex)

Case "RP Report Via Open Cases"
    RpStartDate.Enabled = False
    RpEndDate.Enabled = False
    RpStartDate.Visible = False
    RpEndDate.Visible = False
            
    '... other controls Enabled state
        
Case "RP Report Case Via Officer", "RP Report Via Officer and Action Date", "RP Hazards Sorted via Rating", "RP Hazards Sorted Via Officer"
    RpStartDate.Enabled = True
    RpEndDate.Enabled = True
    RpStartDate.Visible = True
    RpEndDate.Visible = True
    '... other controls Enabled state
End Select

End Sub

Thanks again [bigsmile]

Kind regards

Triacona
 
I start almost every application with tables:
[tt][blue]
ztblReports (names of reports)
==================
rptRptName (name of report)
rptTitle (friendly name displayed in list box of reports)
rpt.... (other fields)

ztblCriteria (names of controls)
================================
criCrit (Name of Control)
criTitle (friendly name)
criFieldName (field name this is used against)

ztblReprotCriteria (junction table of reports vs criteria)
================================
rpcCrit (links to ztblCriteria.criCrit)
rpcRptName (links to ztblReports.rptRptName)
[/blue][/tt]

I have a couple simple forms for maintaining the above records.

I enter "crit" in the tag property of every criteria control on my form.
The after update event of the report list box has this code to enable or disable criteria controls based the selected report.

Code:
Private Sub lboReport_AfterUpdate()
    Dim ctl As Control
    Dim strRpt As String
    strRpt = Me.lboReport
    For Each ctl In Me.Controls
        If Left(ctl.Tag, 4) = "crit" Then
            ctl.Enabled = DCount("*", "ztblReportCriteria", _
            "rpcCrit='" & ctl.Name & "' AND rpcRptName ='" & strRpt & "'")
        End If
    Next
End Sub

I have other code when opening a report that builds a WHERE CONDITION based on enabled criteria controls and the criFieldName values.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top