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

Dynamic Combo Box on Access form 2

Status
Not open for further replies.

Junkie88

Technical User
Mar 1, 2008
60
US
I want a combo box on my form to sometimes show the following value list:
a
b
c
d

and sometimes I want it to show the following only:
x
y

How do I dynamically change the value list of the combo box on the form?
 




Hi,

Clear and AddItem.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
or perhaps:
Code:
[blue]Public Sub NewRowSource([purple][b]idx[/b][/purple])
   [green]'idx = 1 = "a;b;c;d"
   'idx = 2 = "x;y"[/green]
   
   Me!ComboboxName.RowSource = Choose([purple][b]idx[/b][/purple], "a;b;c;d", "x;y")
   
End Sub[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
i have to make some more additions to the new rowsource of the combo box on the form. the combo box is not only going to have dynamic value list but it will also have 2 columns and the entries in the value list are more than just single letters. The first column will be hidden and will not show up once i use the arrow to drop the list down. How can I do this?

so here is what i have in mind. The combo box will either show:

1 agree
2 disagree
3 neutral

or

1 yes
2 no

Note that the first column of these value lists will be hidden. How can i accomplish such a dynamic combo box?

 
What i would do is make a table

fields
Id
AnswereAgree
AnswereYesno


columns on the combo box 2
Code:
function changeRowsource(FieldName)

changeRowsource= "Select id ," & FieldName & from Tablename where" &  FieldName & ">''"


end function
and put this code when you want to change the rowsource
Code:
me.combobox.rowsource=changeRowsource("fieldname")


 
Junkie88 . . .

You don't need a table! (sorry [blue]pwise[/blue])

For [blue]Value List[/blue], columns pairs are defined by the [blue]Column Count[/blue] property. The list just has to be entered in [blue]pair count![/blue] This changes the routine to:
Code:
[blue]Public Sub NewRowSource([purple][b]idx[/b][/purple])
   [green]'idx = 1 = "1;Agree;2;Disagree;3;Neutral"
   'idx = 2 = "1;yes;2;No"[/green]
   
   Me![purple][B][I]ComboboxName[/I][/B][/purple].RowSource = Choose([purple][b]idx[/b][/purple], "1;Agree;" & _
                                           "2;Disagree;" & _
                                           "3;Neutral", _
                                           "1;yes;" & _
                                           "2;No")
[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
aceman:

I know that you could do without a table bt when you start working with a id and tomorrow you could have a third type of answere it is much eaiser to change this to rowsource type table and work with a table
 
hi i am getting the compile error
expected variable or procedure not a module

in the following code:
On Error GoTo Err_btnQuestionnaires_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim res As Integer
Dim ans As Integer

res = RunQuery(1, txtPatientID.Value, Date, txtSessionID.Value)
ans = NewRowSource(1)
res = TextBoxVisible(1)
btnMainMenu.SetFocus

If (check04.Visible <> True) Then
check04.Visible = True
End If

Exit_btnQuestionnaires_Click:
Exit Sub

Err_btnQuestionnaires_Click:
MsgBox Err.Description
Resume Exit_btnQuestionnaires_Click
 
pwise . . .

I would've went for table myself (table changes would be easier than redistributing code), however, considering the [blue]lists[/blue] presented, it look likes they're pretty much set.


Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
can anyone tell me what am i getting the error in the above code at line
ans = NewRowSource(1)

NewRowSource is a module and the error is saying that the compiler was expecting a variable here not a module.

Can anyone tell me why?
 
Junkie88 . . .

[ol][li]You can't give a module the same name as a routine or function! [blue]Rename the module.[/blue][/li]
[li][blue]NewRowSource[/blue] is a subroutine, not a function, and doesn't return anything.[/li][/ol]
In any case there are other errors. Start a new post so others can benefit!

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
aceman:

Don"t worry tomorrow Junkie88 is going to ask how to add these answeres to the dropdown

This Week
Next Week
Next Month
Dont Know
.....

Daily
Weekly
Monthly
....


 
pwise . . .

Indeed! [surprise]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top