472,127 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

How to give an SQL statement in combobox(Visual basic 6.0)

Hi everyone..

I want to insert a combobox with the list of test names of a database, but the testname contains 15000+ data, and I cant type all the data. so can any one help me in writing an SQL statement, so that if I give that statement it will automatically swaps the table names to the combobox.

P.S I know the SQL statement but I dono where to give that SQL statement in combobox

explanation with program will be verymuch helpfull for me

Thanks in advance

Mar 31 '09 #1
5 5943
8,127 Expert 4TB
you just need to go 1...2...3

1.Create a connection
2. open the recordset
3. in a loop add the items from recordset to combobox.
Mar 31 '09 #2
haaa....I am totally new to Visual basic....I am not able to understand what you are telling...can you explain in detail...plzz...I have done some program to extract the data...in the program if you look at the SQL statement(underlined) I want to insert all the values of fullname into the combo box, so that if I select one of the fullname then the data regarding that fullname should be extracted and should be displayed after pressing the Ok button

Private Sub Okbutton_Click()
On Error Resume Next

Dim sConnect As String
Dim db As Database
Dim rs As Recordset
Dim Ws As Workspace
'Dim ID As Double
'Dim doubleID1 As Double
Dim intstring As String

Set Ws = DBEngine.Workspaces(0)

sConnect = "ODBC;DSN=WinUTMS_RT_DB;UID=Localhost;PWD=;Databas e=WinUTMS_RT_DB;"

Set db = Ws.OpenDatabase("", 0, 0, sConnect)

Set rs = db.OpenRecordset("SELECT Fullname FROM abssubtest")
Do While Not rs.EOF
'ID = rs!Messwert
'doubleID1 = rs!UPLimWert
intstring = rs.Fields("Fullname")
End Sub
Mar 31 '09 #3
I have made some changes to your loop....

Expand|Select|Wrap|Line Numbers
  1. Do While Not rs.EOF
  2. 'ID = rs!Messwert
  3. 'doubleID1 = rs!UPLimWert
  4. combo1.add (rs.Fields("Fullname"))
  5. rs.MoveNext
  6. Loop
  7. End Sub
Apr 4 '09 #4
Private Sub Combo1_Click()

Label1.Caption = "find" & Combo1.Text
Label1.Visible = True

End Sub

Private Sub Form_Load()
On Error Resume Next

Label1.Visible = False
DataGrid1.Visisble = False

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = New ADODB.Connection
cn.ConnectionString = "ODBC;DSN=WinUTMS_RT_DB;UID=Localhost;PWD=;Dat abas e=WinUTMS_RT_DB;"

Set rs = New ADODB.Recordset
rs.Open "absprfg", cn, adOpenKeyset, adLockPessimistic, adCmdTable

Do While Not rs.EOF
Combo1.AddItem rs.Fields("Modus")
If Not (rs.EOF And rs.BOF) Then
End If
End Sub
Private Sub Command1_Click()
On Error Resume Next
Me.Form.RecordSource = "SELECT Fullname FROM abssubtest & ComboBox.Value & " ';"

End Sub

Private Sub Label1_Click()
DataGrid1.Visible = True

Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select absprfg.Modus From absprfg WHERE absprfg.Modus='" & Combo1.Text & "' "

End Sub
I have done the above program..but after pressing the run button..I am getting the blank screen and after some time the vb is not responding and I have to close the program...even I have seen it with break point but of no use....can you please tell me where I have done the mistake...

Apr 6 '09 #5
I think at this line your are having problem.
Expand|Select|Wrap|Line Numbers
  1. Me.Form.RecordSource = "SELECT Fullname FROM abssubtest & ComboBox.Value & " ';"
Apr 6 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Steffen Laser | last post: by
2 posts views Thread by jaYPee | last post: by
6 posts views Thread by Juan Pedro Gonzalez | last post: by
10 posts views Thread by news.microsoft.com | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.