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
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