Hi:
I have a problem.. I have 3 text boxes and 12 comboboxes. the idea of the form is that the data entry on form has to be stored in Access.. which happens.. but i to limit the user in choosing only the values available from the combo boxes and not let the user enter any value into the combobox other than the values available in the pull down.
How do i achieve this here?
Imports System.data
Imports System.Data.oledb
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Using con As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=Z:\CAD\Copy of USERS.mdb")
con.Open()
Dim objcmd As New Data.OleDb.OleDbCommand
Button1.BackColor = System.Drawing.Color.CornflowerBlue
Button2.BackColor = System.Drawing.Color.Bisque
Dim TableName As String = ""
Dim query As String = ""
Dim cbo As ComboBox = Nothing
Dim objrdr As Data.OleDb.OleDbDataReader
For x As Int32 = 1 To 12
Select Case x
Case 1
query = "SELECT DISTINCT [Group] FROM table1 WHERE [Group] IS NOT NULL ORDER BY [Group]"
TableName = "Group"
cbo = ComboBox1
Case 2
query = "SELECT DISTINCT NXVERSION FROM table1 WHERE NXVERSION IS NOT NULL ORDER BY NXVERSION"
TableName = "NXVERSION"
cbo = ComboBox2
Case 3
query = "SELECT DISTINCT ANSYS FROM table1"
TableName = "ANSYS"
cbo = ComboBox3
Case 4
query = "SELECT DISTINCT MECH FROM table1"
TableName = "MECH"
cbo = ComboBox4
Case 5
query = "SELECT DISTINCT MACH FROM table1"
TableName = "MACH"
cbo = ComboBox5
Case 6
query = "SELECT DISTINCT UGSTRUCTURES FROM table1"
TableName = "UGSTRUCTURES"
cbo = ComboBox6
Case 7
query = "SELECT DISTINCT MFG FROM table1 WHERE MFG IS NOT NULL ORDER BY MFG"
TableName = "MFG"
cbo = ComboBox7
Case 8
query = "SELECT DISTINCT MAKE FROM table1 WHERE MAKE IS NOT NULL ORDER BY MAKE"
TableName = "MAKE"
cbo = ComboBox8
Case 9
query = "SELECT DISTINCT OSPATCHES FROM table1 WHERE OSPATCHES IS NOT NULL"
TableName = "OSPATCHES"
cbo = ComboBox9
Case 10
query = "SELECT DISTINCT RAM FROM table1 WHERE RAM IS NOT NULL ORDER BY RAM"
TableName = "RAM"
cbo = ComboBox10
Case 11
query = "SELECT DISTINCT GRAPHICSCARD FROM table1 WHERE GRAPHICSCARD IS NOT NULL ORDER BY GRAPHICSCARD"
TableName = "GRAPHICSCARD"
cbo = ComboBox11
Case 12
query = "SELECT DISTINCT GRAPHICSVERSION FROM table1 WHERE GRAPHICSVERSION IS NOT NULL ORDER BY GRAPHICSVERSION"
TableName = "GRAPHICSVERSION"
cbo = ComboBox12
End Select
objcmd.Connection = con
objcmd.CommandText = query
objrdr = objcmd.ExecuteReader
cbo.Items.Clear()
If objrdr.HasRows Then
Do While objrdr.Read
cbo.Items.Add(objrdr.GetValue(0))
Loop
End If
objrdr.Close()
Next
End Using
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=Z:\CAD\Copy of USERS.mdb")
Dim cmd As OleDbCommand
Dim icount As Integer
Dim str As String
con.Open()
str = "insert into table1 VALUES(' " & TextBox1.Text & "', ' " & TextBox2.Text & "',' " & TextBox3.Text & "', ' " & ComboBox1.SelectedItem & "', '" & ComboBox2.SelectedItem & "',' " & ComboBox3.SelectedItem & "', ' " & ComboBox4.SelectedItem & "', '" & ComboBox5.SelectedItem & "',' " & ComboBox6.SelectedItem & "','" & ComboBox7.SelectedItem & "',' " & ComboBox8.SelectedItem & "',' " & ComboBox9.SelectedItem & "', '" & ComboBox10.SelectedItem & "', ' " & ComboBox11.SelectedItem & "', '" & ComboBox12.SelectedItem & "')"
cmd = New OleDbCommand(str, con)
icount = cmd.ExecuteNonQuery
MessageBox.Show(icount)
con.Close()
End Sub
Private Sub ComboBox7_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox7.SelectedIndexChanged
Using con As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=Z:\CAD\Copy of USERS.mdb")
con.Open()
If (ComboBox7.Text = "DELL") Then
ComboBox8.Items.Clear()
ComboBox8.Items.Add("PRECISION WORKSTATION 670")
ComboBox8.Items.Add("PRECISION WORKSTATION 690")
ComboBox8.Items.Add("PRECISION WORKSTATION 650")
ComboBox8.Items.Add("PRECISION WORKSTATION 470")
ComboBox8.Items.Add("PRECISION WORKSTATION M65")
ComboBox8.Items.Add("PRECISION WORKSTATION 530")
ComboBox8.Items.Add("PRECISION WORKSTATION 550")
ElseIf (ComboBox7.Text = "HP") Then
ComboBox8.Items.Clear()
ComboBox8.Items.Add("HP xw6400 WORKSTATION")
ComboBox8.Items.Add("HP xw6600 WORKSTATION")
ComboBox8.Items.Add("HP xW4400 WORKSTATION")
End If
con.Close()
End Using
End Sub
End Class