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

Recommended Answers

All 5 Replies

Set DropDownStyle = DropDownList on combo box properties.

Hi Jx_man thanks for ur reply..

did u mean ..in Access or VB ?


Set DropDownStyle = DropDownList on combo box properties.

got it thanks..it works! :)


Hi Jx_man thanks for ur reply..

did u mean ..in Access or VB ?

One other problem is .. my selections dont get refreshed.. previous selections remain in the comboboxes..how do i get rid of that ?

l have three comboboxes, combobobox1,combobox2 and combobo3. l have items like price,firstname and community in combobox1.l have comparator operators like = ,>,<,<=,Like in combobox2. l want to populate my combobox3 from mdb database by using the items in combobox1 and combobox2 for eg if combobox1.selecteditem="firstname"and combobox2.selected item="like" then Dim da As New OleDbDataAdapter
Dim cnn As OleDbConnection
Dim cmd As OleDbCommand
Dim a As Integer
Dim ds As New DataSet
cnn = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=D:\GIS\PERSONAL\CBO\CBO1.mdb")

If cnn.State = ConnectionState.Closed Then cnn.Open()

cmd = cnn.CreateCommand
cmd.CommandText = "SELECT * FROM members"
da.SelectCommand = cmd
da.Fill(ds, "members")
cnn.Close()
ComboBox3.Text = ds.Tables(0).Rows(a).Item(1)
Dim r As DataRow
ComboBox3.Items.Clear()
For Each r In ds.Tables(0).Rows
ComboBox3.Items.Add(r.Item(1))
Next r

Catch ex As Exception
MsgBox(ex.ToString())
End Try
but it is not working. Can somebody help please!

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.