P
PGM
I am trying to populate a combo box using a simple SQL query to a database
but all I get in the combo box is "System._ComObject" . Any suggestions are
greatly appreciated
On Error Resume Next
Dim strSQL As String
Dim strConn As String
Dim i As Integer
strSQL = "SELECT F2 FROM dbo.Masterserver WHERE F2 like 't%'"
strConn = "Provider=SQLOLEDB.1;Password=vbuser;Persist Security
Info=True;User ID=VBuser;Initial Catalog=Masterserver;Data
Source=patmtest\sqlexpress"
MyConnObj = New ADODB.Connection
MyConnObj.Open(strConn)
cmdselect = New ADODB.Command
cmdselect.ActiveConnection = MyConnObj
cmdselect.CommandText = strSQL
myRecSet = New ADODB.Recordset
myRecSet.Open(strSQL, MyConnObj, ADODB.CursorTypeEnum.adOpenKeyset,
ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
MsgBox("Total Number of records = " & myRecSet.RecordCount) 'Test SQL query
ComboBox1.Refresh()
myRecSet.MoveFirst()
For i = 1 To myRecSet.RecordCount
ComboBox1.Items.Add(myRecSet.Fields("F2"))
Next i
myRecSet.Close()
MyConnObj.Close()
myRecSet = Nothing
MyConnObj = Nothing
but all I get in the combo box is "System._ComObject" . Any suggestions are
greatly appreciated
On Error Resume Next
Dim strSQL As String
Dim strConn As String
Dim i As Integer
strSQL = "SELECT F2 FROM dbo.Masterserver WHERE F2 like 't%'"
strConn = "Provider=SQLOLEDB.1;Password=vbuser;Persist Security
Info=True;User ID=VBuser;Initial Catalog=Masterserver;Data
Source=patmtest\sqlexpress"
MyConnObj = New ADODB.Connection
MyConnObj.Open(strConn)
cmdselect = New ADODB.Command
cmdselect.ActiveConnection = MyConnObj
cmdselect.CommandText = strSQL
myRecSet = New ADODB.Recordset
myRecSet.Open(strSQL, MyConnObj, ADODB.CursorTypeEnum.adOpenKeyset,
ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
MsgBox("Total Number of records = " & myRecSet.RecordCount) 'Test SQL query
ComboBox1.Refresh()
myRecSet.MoveFirst()
For i = 1 To myRecSet.RecordCount
ComboBox1.Items.Add(myRecSet.Fields("F2"))
Next i
myRecSet.Close()
MyConnObj.Close()
myRecSet = Nothing
MyConnObj = Nothing