I want to translate this to vba. This is my code in vb.net using ms access as database.
Code:
Call myCn()
Dim stat As String
Try
Dim i As Integer
For i = 0 To cb_wetstalls.Items.Count Step 1
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("SELECT *")
xSQL.AppendLine("FROM tbl_stall")
xSQL.AppendLine("WHERE StallID = '" & cb_wetstalls.Items(i) & "'")
Using cn As New OleDbConnection(ConString)
cn.Open()
Dim cmd As New OleDb.OleDbCommand(xSQL.ToString, cn)
dr = cmd.ExecuteReader
If dr.HasRows = True Then
While dr.Read()
stat = (dr(4).ToString)
End While
If stat = "Available" Then
btnarray(i).backcolor = Color.LightSalmon
ElseIf stat = "Lease" Then
btnarray(i).backcolor = Color.LimeGreen
ElseIf stat = "Rent" Then
btnarray(i).backcolor = Color.Yellow
End If
Else
End If
cmd.Dispose()
'dr.Close()
End Using
Next
Catch ex As Exception
End Try
I have a combo box in access populated from a table. It contains ID.
I want to loop through each item in combobox and check its corresponding status in the table.
After checking status it shall select which bakcolor is applicable.
In access I use label for it. Can somebody guide me on how to convert my code.
Please see image below. Thanks in advance.