How do you add items like for example in a combobox we use this code
//this is the code for combobox
If ComboBox1.SelectedItem = "A" Then
ComboBox2.Items.Add("101")
ComboBox2.Items.Add("102")
Else
If ComboBox1.SelectedItem = "B" Then
ComboBox2.Items.Add("201")
ComboBox2.Items.Add("202")
End If
End If
//this is the code i tried
If BunifuDropdown1.selectedValue = "A" Then
BunifuDropdown2.Items.add("101")
BunifuDropdown2.Items.add("102")
Else
If BunifuDropdown1.selectedValue = "B" Then
BunifuDropdown2.Items.add("201")
BunifuDropdown2.Items.add("202")
End If
End If
I need a code like this for BunifuDropdown1
please help!
Related
i have a ms access formular where there are given several Information. For "Status" Combobox there are several options like "1","2","3","4". If "4" is selected in "cbx_Status" then I want to add in Textbox "txt_ID_Order" an automatically increased ID and give an Order Time in textbox "txt_OrderTime". That's why I wrote this and works well:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.cbx_Status.Value = "4" Then
Me.txt_OrderTime = Now()
Me.txt_ID_Order = DMax("[ID_Order]", "tblX") + 1
Else:
Me.txt_ID_Order=""
Me.txt_OrderTime = ""
End If
End Sub
However, if Status "4" is for some reason changed and again selected , I want to keep that old ID. But right know wenn i do that, it's still increasing ID.
How can I fix it?
Thanks
Check for a value:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me!cbx_Status.Value = "4" Then
If IsNull(Me!txt_OrderTime.Value) Then
Me!txt_OrderTime.Value = Now()
Me!txt_ID_Order.Value = DMax("[ID_Order]", "tblX") + 1
End If
Else
Me!txt_ID_Order.Value = Null
Me!txt_OrderTime.Value = Null
End If
End Sub
Not sure about the logic though; if you select anything else than 4, the textboxes will be cleared.
For Each row As DataRow In ds.Tables(0).Rows
If (row("Flag") And 1 = 1) Then
row("Col_1") = Color.Red
End If
If (row("Flag") And 2 = 2) Then
row("Col_2") = Color.Red
End If
If (row("Flag") And 4 = 4) Then
row("Col_3") = Color.Red
End If
If (row("Flag") And 8 = 8) Then
row("Col_4") = Color.Red
End If
Next
I would like to set a specific cell to red based on a flag. I have access to a DataSet and DataGrid, but not DataGridView. Is there a simple way to accomplish this with DataGrid? I believe what I have now doesn't work as the DataRow is just memory data.
why are you using 1=1 , just use True ... wait a minute
looking at your code again ... you are doing bit manipulation ... i think that you are missing some brackets in your if statements
should be If ((row("Flag") And 1) = 1) Then .... same for the rest
I have created a listview and populated it using datatable..
All worked fine... Now I added checkbox to all items..
Now I want like when the last column's value of an item is "true" then the checkbox of the same item is checked.
I tried the following code...
If LstViewHelp.Items.Count <> 0 Then
For Each item As ListViewItem In LstViewHelp.Items
If LstViewHelp.FocusedItem.SubItems(10).Text = "True" Then
LstViewHelp.FocusedItem.Checked = True
End If
Next
End If
I am getting the following error object reference is not set to an instance.
Tried many links but no proper solution found...!
You can get all selected index like ListView.SelectedIndexCollection using SelectedIndices . Add ForEach loop on selected indexes and edit your SubItem.
Dim indexes As ListView.SelectedIndexCollection = Me.ListViewHelp.SelectedIndices
For Each index In indexes
If Me.ListViewHelp.Items(index).SubItems(10).Text = "True" Then
LstViewHelp.Items(index).Checked = True
End If
Next
And if you want to check all items you can use for loop
For i = 0 To Me.ListViewHelp.Items.Count - 1
If Me.ListViewHelp.Items(i).SubItems(10).Text = "True" Then
LstViewHelp.Items(i).Checked = True
End If
Next
I tried to write two If statements inside each other in VBA, but it gives me wrong answer. When I debug it, it shows that the program doesn't go through the ElseIf and keeps going with the else of the first If.
How can I have two If statements working properly inside each other?
Code:
If ConfigBox.Value <> ... Then
If ListBox1.Value = ... Then
DO SOMETHING
Else
DO SOMETHING
End If
ElseIf ListBox1.Value = ... Or ListBox1.Value = ... Then
DO SOMETHING
Else
DO SOMETHING
End If
Your nesting is a bit off. You would want to do something like this:
If ConfigBox.Value <> ... Then
If ListBox1.Value = ... Then
Code
ElseIF ListBox1.Value = ... Or ListBox1.Value = ... Then
Code
Else
Code 'if ListBox1.Value doesn't meet above criteria
End If
Else
Code 'if ConfigBox criteria is not met. You could start another nested If for the ListBox1 here too.
End If
try with below
If ((ConfigBox.Value <> "1") And (ListBox1.Value = "2")) Then
'Do Something
ElseIf ((ConfigBox.Value <> "1") And (ListBox1.Value <> "2")) Then
'Do Something
ElseIf ListBox1.Value = "3" Or ListBox1.Value = "4" Then
'Do Something
Else
'Do Something
End If
I have searched everywhere for an answer to this issue and I am fairly new to VBA so I hope you can help. Below is the code.
If [e19].Value + [g19].Value = [c19].Value Then
[l19].Value = "Yes"
ElseIf [e19].Value = "N/A" Then
[l19].Value = "N/A"
**ElseIf Range("i18:i21, l18").Value = "{a}" Then**
l19.Value = "{b}"
The code wrapped in ** is where I am having my issue. Any ideas?
Thank you
You can't compare a range with a specific value.. You could take each cell inside a 'For Each xxx In Range.Cells...Next' statement to proceed to the comparison for each value inside the range, but note that each cell is compared individually, in turn. This code should work this way:
Sub zo()
If [e19].Value + [g19].Value = [c19].Value Then
[l19].Value = "Yes"
ElseIf [e19].Value = "N/A" Then
[l19].Value = "N/A"
Else
For Each cell In Range("i18:i21, l18")
If cell.Value = "{a}" Then
[l19].Value = "{b}"
End If
Next
End If
End Sub