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

combo box problem

Status
Not open for further replies.

djmc

Programmer
Jun 12, 2002
179
CA
I have a combo box which could have 2 different record sources, I set these record sources dynamically which is dependant on another combo box choice. One record source has 2 columns shown in the combo box the other has 1.

When I first get the combo box to uses the recordsource which contained 2 columns, and then change the recordsource to the one with 1 column, I get the error:

The value you entered isn't valid for this field.
For example, you may have entered text in a numeric field.

If I assign the recordsource the other way around (one with column 1 first, then the 2 column one) the error does not occur.

Another funny thing is that if I assign the recordsource with the 2 column value list first, the selected value is aligned to the right, where as it would be aligned left with the 1 column value list if it was assigned first.

Here is the code which selects the recordsource:

Private Sub cboType_AfterUpdate()

' Allow user to choose chain/channel parameter with reference to chain/channel name
Select Case cboType
Case "Chain"
cboParameter = ""
cboParameter.Visible = True
cboParameter.RowSource = "SELECT ChainNo, ChainName FROM [Chain Information]"
cboParameter.ColumnCount = 2
cboParameter.ColumnWidths = "1cm;5cm"

Case "Channel"
cboParameter = ""
cboParameter.Visible = True
cboParameter.RowSource = "SELECT DISTINCT Type FROM [Channel]"
cboParameter.ColumnCount = 1
cboParameter.ColumnWidths = "7cm"
Case Else
cboParameter.Visible = False
End Select
txtParameter = ""
End Sub
 
Hallo,

Sounds like you're pushing the boundaries of what Access can do with form design on the fly.

What about having two separate combo boxes, in the same place and only make one visible depending on the state of the other combo box.

- Frink
 
Or try changing the code to

Case "Channel"
cboParameter = ""
cboParameter.Visible = True
cboParameter.RowSource = "SELECT DISTINCT null as Spare, Type FROM [Channel]"

so that you don't need to change the column count.

hth

Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top