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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATA DISPLAYED ON COMBO BOX DEPENDING ON CONDITION 2

Status
Not open for further replies.

villica

Programmer
Feb 25, 2000
332
0
0
CA
I have a form with a combo box that displays number as 00001 etc and also numbers such as dc00001 etc

When the form is loades both type of numbers are displayed on the form
for example 00001
00002
00003
dc0001
dc0002 etc


On the form I also have two selection boxes

1 cco
2 dev

I would like to do the following. If the user checks the cco I would like the combo box to displays numbers that stars WITHOUT THE DC DC at front


If the users selects dev, I would like the combo box to display only the numbers that BEGIN WITH DC at front. Is this possible in access. Thanks to everyone who has helped in the past
 
Well, since that makes cco and dev mutually exclusive, I'd consider changing them to radio buttons. That way they couldn't both be selected or unselected.

But what you want is something like this. Let's say the combo box's Row Source property is set to a table name, 'tblSource'. You want to create Click event procedures for the check boxes:
Code:
    Private Sub cco_Click()
        If cco Then
            Combo1.RowSource = "SELECT Data FROM tblSource WHERE Data NOT LIKE 'dc*'"
        End If
        dev = False
    End Sub
    Private Sub dev_Click()
        If dev Then
            Combo1.RowSource = "SELECT Data FROM tblSource WHERE Data LIKE 'dc*'"
        End If
        cco = False
    End If
Rick Sprague
 
Rick thank you for you reply. I tried the above and there are two thing happening. When I click on cco I get everything for some reason it does not take the NOT LIKE. The second thing is that when I click on the on dev the first number is 00000 but the rest on numbers on the combo box start with dc . Any other suggestions
 
You may possibly need to put "Combo1.Requery" at the end of each routine. I didn't think it was needed when you change the Row Source, though.

How about copying your code and pasting it here? Rick Sprague
 
Rick-

Tried your suggestion using an option group with the following AfterUpdate event.
It works fine. Something else is going on in Villica's app that we're apparently not seeing (maybe dropping the single quotes, e.g. LIKE 'dc*')

Bob

****************************************

Private Sub grpSelType_AfterUpdate()
Dim strSQL As String

strSQL = "SELECT DISTINCT data FROM tblSource "

If Me!grpSelType = 1 Then 'cco selected
strSQL = strSQL & "WHERE Data NOT LIKE 'dc*';"
Else 'dev selected
strSQL = strSQL & "WHERE Data LIKE 'dc*';"
End If

With Me!cbo0
.RowSource = strSQL
.SetFocus
.Dropdown
End With
End Sub
 
Thanks you both of you, I was putting my code under got focus under every option and I think it was getting all confuse. It is now working, there is only 1 minor detail that I am not sure whether or not there is a solution for.
When I clik on dev this is the way it shows the combo box drops down 000001
dc0001
dc0002

Is there a way to make so that is not dc0001.

thanks again
 
I don't understand. You said that when you click on dev you want all numbers that start with "dc". Now are you saying you don't want all of the "dc" numbers? Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top