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!

Set default value in a list

Status
Not open for further replies.

Triacona

Technical User
Jun 11, 2009
462
GB
Dear All,

I have a form which has tabs.
The first Tab About; is the tab I want to focus on.
I have a list on this tab, with 2 entries:
About?
Input

Based on this I have a case select senario:
Code:
Private Sub ListAbout_AfterUpdate()

   Select Case ListAbout.ItemData(ListAbout.ListIndex)
   
        Case "About?"
            StartDate.Enabled = False
            EndDate.Enabled = False
            StartDate.Visible = False
            EndDate.Visible = False
            StartDateLb.Visible = False
            EndDateLb.Visible = False
            CmbOffLb.Visible = False
            CmbOff.Visible = False
            CmbStatLb.Visible = False
            CmbStat.Visible = False
            DcCmbTypLb.Visible = False
            DcCmbTyp.Visible = False
            EnCmbTypLb.Visible = False
            EnCmbTyp.Visible = False
            AddSrch.Visible = False
            AddSrchLb.Visible = False
            SrchCritLb.Visible = False
            SrchCrit.Visible = False
            AboutLb.Visible = True
            InputLb.Visible = False
            
            
            Case "Input"
            StartDate.Enabled = True
            EndDate.Enabled = True
            StartDate.Visible = True
            EndDate.Visible = True
            StartDateLb.Visible = True
            EndDateLb.Visible = True
            CmbOffLb.Visible = True
            CmbOff.Visible = True
            CmbStatLb.Visible = True
            CmbStat.Visible = True
            DcCmbTypLb.Visible = False
            DcCmbTyp.Visible = False
            EnCmbTypLb.Visible = False
            EnCmbTyp.Visible = False
            AddSrch.Visible = False
            AddSrchLb.Visible = False
            SrchCritLb.Visible = False
            SrchCrit.Visible = False
            AboutLb.Visible = False
            InputLb.Visible = True
    End Select
    
End Sub
I have the following code above the code above:
Code:
Private Sub ListAbout_BeforeUpdate(Cancel As Integer)

If ListAbout = "" Then
    DoCmd.SelectObject(acDefault, [ListAbout].ItemsSelected.Item) = "About?"
End If
'ListAbout.BeforeUpdate = ListAbout.DefaultValue = "About?"

End Sub

What I want is for the default selected item in the list, to be About?.
It seems to be ignoring my code.
Any help would be greatly appreciated [bigsmile]
Kind regards
Tiacona
 
How 'bout
Code:
Private Sub ListAbout_BeforeUpdate(Cancel As Integer)

If nz(ListAbout,"") = "" Then ListAbout="About?"
 
End Sub
 
How are ya Triacona . . .

If your talking a [blue]listbox[/blue] there are two ways:
[ol][li]In form design view, set the [blue]Default[/blue] property of the listbox to [blue]"About?"[/blue]. Close the form then open to see the selected default.[/li]
[li]Thru VBA using:
Code:
[blue]   ListAbout.Selected(0) = True[/blue]
[/li][/ol]
Where to put the code depends on what your trying to do. Let us know.

In both cases rem out or remove the [blue]Before Update[/blue] event as its not needed. I'm surprised it didn't cause an error!

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Dear TheAceMan1 and pwise,

Thank you very much for your replies [bigsmile] [2thumbsup]

I have used "About?" in the default box and removed the VB code and it works! yay!!

I wanted when the Access Program started up for the main form to be displayed with the About selected, so that it would then display a text box with the about information.
The user then would click on other tabs and as in my About tab, there would be lists they could choose from and depending on their selection within that list (Case Select), certain fields would appear and dissappear, as with the About tab, if the user clicks on About? then the about text box displayes, if they click on input an example of all the input fields are displayed.

Thanks ever so much for your help peeps! [smile]
Kind regards
Triacona
Sometimes the simplest answer is the best and most practical
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top