954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

value in combo box is choose

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.

hueikar
Light Poster
29 posts since Nov 2010
Reputation Points: 14
Solved Threads: 0
 

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
hkdani
Posting Pro in Training
435 posts since Nov 2007
Reputation Points: 49
Solved Threads: 47
 

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?

hueikar
Light Poster
29 posts since Nov 2010
Reputation Points: 14
Solved Threads: 0
 

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
hkdani
Posting Pro in Training
435 posts since Nov 2007
Reputation Points: 49
Solved Threads: 47
 

yeah.thnx for ur suggestion.

hueikar
Light Poster
29 posts since Nov 2010
Reputation Points: 14
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You