i'm trying to get the combobox to come back with my list of customer name, p21_view_customer.customer_name. something is wrong and I can't figure it out. Please help.
Code:
Private Sub ComboBox1_Change()
With Application
.Calculation = xlManual
.EnableEvents = False
.ScreenUpdating = False
End With
Dim stSQL As String, sBook As String, rst As ADODB.Recordset, k As Integer, vaData As Variant
Dim objConn As ADODB.Connection
Dim ConnectionString As String
ConnectionString = "Driver={SQL Server}; "
Set objConn = New ADODB.Connection
stSQL = "SELECT [p21_view_customer].[credit_status], [p21_view_customer].[customer_name], [p21_view_customer].[customer_id] " & _
"FROM [dbo].[p21_view_customer] "
With objConn
.CursorLocation = adUseClient
.Open ConnectionString
Set rst = .Execute(stSQL)
End With
With rst
Set .ActiveConnection = Nothing
k = .Fields.Count
vaData = .GetRows
End With
ComboBox1.List = vaData
objConn.Close
Set rst = Nothing
Set objConn = Nothing
End Sub
Last edited by a moderator: