Member Avatar for hueikar

Hi. I am using visual studio with visual basic.
I have create a combo box which data is from oracle.
I want to know how to check the value in combo box is choose before i proceed to save the record? Thank you.

The text property of the combo box returns the current value of the edit box according to MSDN documentation.

So, you must validate your data through code before saving it into your database. In other words, if the text in the edit box has been changed, your program must make sure that that data can actually be saved in that particular field of your oracle recordset.

You can do this in the change event of the combo control. This only works, if the style property is set to 0 or 1.

Private Sub Combo1_Change()
'  Code to validate the new value
End Sub

Otherwise, you'll have to write a function to check the data before saving it to the database.

Private Sub CheckData()
' 
End Sub
Member Avatar for hueikar

Thnx for your advice.
So if i want to check many combo box in the same form. how to write the coding?
If my coding is as below:

Private Sub CheckData()

        If cboxUser.Text = "" Then
            MsgBox("Please insert you username!")
        End If

    End Sub

Then how can i advoid it will saved to data if combo box is empty value?

You could do something like the following. This would prompt for good data. The
variable strAnswer will store the answer from the user. You might want to code
to validate the user's answer, though. This is just a general idea.

Private Sub CheckData()
Dim strAnswer As String
    If Combo1.Text = vbNullString Then
        strAnswer = InputBox("Please, enter proper data", "Data Error", "0")
        If strAnswer = "0" Then
            Exit Sub
        Else
            SaveData strAnswer
        End If
    End If
End Sub

Private Sub SaveData(ByVal GoodData as String)

End Sub
Member Avatar for hueikar

yeah.thnx for ur suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.