J
jonneke
I would like to limit my combobox.
My combobox is called ComboBranches and has 2 columns. The first
column is shown in my form, the second one not because I made the
column wide 0cm. The second column is used to update a list which
shows a selection of names who are coresponding to several comboboxes.
I know you can use limit to list but limit lisst is already on Yes.
Because I use visual basic code to update a list with the following
code:
Sub Command6_Click()
Dim MySQL
Dim Prefix
Dim CountryCondition
Dim PriorityCondition
Dim BrancheCondition
Dim ExistingCondition
Dim ContactsYNCondition
Dim Postfix
Prefix = "SELECT Bank FROM [Data on bank level] WHERE "
If Me.ComboCountry <> "All" Then
CountryCondition = "[Country of interest] = '" &
Me.ComboCountry.Value & "' AND "
End If
If Me.ComboPriority.Value <> "All" Then
PriorityCondition = "[Contact priority] = '" &
Me.ComboPriority.Value & "' AND "
End If
If Me.ComboBranches.Value <> "All" Then
BrancheCondition = Me.ComboBranches & " AND "
End If
If Me.ComboExisting <> "All" Then
ExistingCondition = "[Existing Zurich Partner] = '" &
Me.ComboExisting & "' AND "
End If
If Me.ComboContactsYN.Value <> "All" Then
If Me.ComboContactsYN.Value = "Yes" Then
ContactsYNCondition = "[Data on bank level].[Bank] IN
(SELECT DISTINCT [Data on contact level].[Bank] FROM [Data on contact
level] WHERE [Data on contact level].[Last Name] IS NOT NULL) AND "
End If
If Me.ComboContactsYN.Value = "No" Then
ContactsYNCondition = "[Data on bank level].[Bank] NOT IN
(SELECT DISTINCT [Data on contact level].[Bank] FROM [Data on contact
level] WHERE [Data on contact level].[Last Name] IS NOT NULL) AND "
End If
End If
Postfix = "1=1 ORDER BY Bank;"
MySQL = Prefix & CountryCondition & PriorityCondition &
BrancheCondition & ExistingCondition & ContactsYNCondition & Postfix
Me.ListBank.RowSource = MySQL
Me.Refresh
End Sub
I get a runtime error 2227: the text you entered isn't an item in the
list at Me.Refresh.
Therefore I tried the following code in visual basic when I change the
combobox:
Private Sub ComboBranches_Change()
' Does not work
If (Me.ComboBranches.Value <> "All" And _
Me.ComboBranches.Value <> "[Branches] >= 0 AND [Branches] <
10" And _
Me.ComboBranches.Value <> "[Branches] >= 10 AND [Branches] <
100" And _
Me.ComboBranches.Value <> "[Branches] >= 100 AND [Branches] <
250" And _
Me.ComboBranches.Value <> "[Branches] >= 250 AND [Branches] <
1000" And _
Me.ComboBranches.Value <> "[Branches] >= 1000 AND [Branches] <
2000" And _
Me.ComboBranches.Value <> "[Branches] >= 2000" And
Me.ComboBranches.Value <> "[Branches] IS NULL") Then
MsgBox "The text you entered isn't an item in the list. Please
select an item from the list."
Exit Sub
End If
'store chosen selection
Forms!vars!Branches = Me.ComboBranches.Value
Call Command6_Click
End Sub
But this code does not work. When entering a value different from the
list in the combo box I do not get the error message. I entered a
watch and the watch tells me that the combobox has the previous
correct value. Does anyone know how to solve this problem?
My combobox is called ComboBranches and has 2 columns. The first
column is shown in my form, the second one not because I made the
column wide 0cm. The second column is used to update a list which
shows a selection of names who are coresponding to several comboboxes.
I know you can use limit to list but limit lisst is already on Yes.
Because I use visual basic code to update a list with the following
code:
Sub Command6_Click()
Dim MySQL
Dim Prefix
Dim CountryCondition
Dim PriorityCondition
Dim BrancheCondition
Dim ExistingCondition
Dim ContactsYNCondition
Dim Postfix
Prefix = "SELECT Bank FROM [Data on bank level] WHERE "
If Me.ComboCountry <> "All" Then
CountryCondition = "[Country of interest] = '" &
Me.ComboCountry.Value & "' AND "
End If
If Me.ComboPriority.Value <> "All" Then
PriorityCondition = "[Contact priority] = '" &
Me.ComboPriority.Value & "' AND "
End If
If Me.ComboBranches.Value <> "All" Then
BrancheCondition = Me.ComboBranches & " AND "
End If
If Me.ComboExisting <> "All" Then
ExistingCondition = "[Existing Zurich Partner] = '" &
Me.ComboExisting & "' AND "
End If
If Me.ComboContactsYN.Value <> "All" Then
If Me.ComboContactsYN.Value = "Yes" Then
ContactsYNCondition = "[Data on bank level].[Bank] IN
(SELECT DISTINCT [Data on contact level].[Bank] FROM [Data on contact
level] WHERE [Data on contact level].[Last Name] IS NOT NULL) AND "
End If
If Me.ComboContactsYN.Value = "No" Then
ContactsYNCondition = "[Data on bank level].[Bank] NOT IN
(SELECT DISTINCT [Data on contact level].[Bank] FROM [Data on contact
level] WHERE [Data on contact level].[Last Name] IS NOT NULL) AND "
End If
End If
Postfix = "1=1 ORDER BY Bank;"
MySQL = Prefix & CountryCondition & PriorityCondition &
BrancheCondition & ExistingCondition & ContactsYNCondition & Postfix
Me.ListBank.RowSource = MySQL
Me.Refresh
End Sub
I get a runtime error 2227: the text you entered isn't an item in the
list at Me.Refresh.
Therefore I tried the following code in visual basic when I change the
combobox:
Private Sub ComboBranches_Change()
' Does not work
If (Me.ComboBranches.Value <> "All" And _
Me.ComboBranches.Value <> "[Branches] >= 0 AND [Branches] <
10" And _
Me.ComboBranches.Value <> "[Branches] >= 10 AND [Branches] <
100" And _
Me.ComboBranches.Value <> "[Branches] >= 100 AND [Branches] <
250" And _
Me.ComboBranches.Value <> "[Branches] >= 250 AND [Branches] <
1000" And _
Me.ComboBranches.Value <> "[Branches] >= 1000 AND [Branches] <
2000" And _
Me.ComboBranches.Value <> "[Branches] >= 2000" And
Me.ComboBranches.Value <> "[Branches] IS NULL") Then
MsgBox "The text you entered isn't an item in the list. Please
select an item from the list."
Exit Sub
End If
'store chosen selection
Forms!vars!Branches = Me.ComboBranches.Value
Call Command6_Click
End Sub
But this code does not work. When entering a value different from the
list in the combo box I do not get the error message. I entered a
watch and the watch tells me that the combobox has the previous
correct value. Does anyone know how to solve this problem?