Hi I am trying to populate a word userform combobox with data from an external excel file:
I keep getting a Syntax error on the FROM clause, I have no idea why?
Thanks
Private Sub UserForm_Activate()
Dim Myconnection As New ADODB.Connection
Dim Myrecordset As New ADODB.Recordset
Myconnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Users\m\Desktop\test list.xls;" & _
"Extended Properties=Excel 8.0;"
Myrecordset.Open "Select Distinct MoniesIn FROM Sheet1$A1:D5000;", Myconnection, adOpenStatic
Myrecordset.MoveFirst
With ActiveSheet.MoniesInDescription
.Clear
Do
.AddItem Myrecordset![MoniesIn]
Myrecordset.MoveNext
Loop Until Myrecordset.EOF
End With
UserForm_Initialize_Exit:
On Error Resume Next
Myrecordset.Close
Myconnection.Close
Set Myrecordset = Nothing
Set Myconnection = Nothing
Exit Sub
UserForm_Initialize_Err:
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
Resume UserForm_Initialize_Exit
End Sub
Bookmarks