I have setup a VBA Userform (in a word document) on Initialize it is set so that a combobox (MoniesInDescription) populates via an external Excel File.
It works all fine, except after I have saved my document and reopen if I try to run the code i get 'Run Time Error 94 : Invalid Use of Null'. I haven't changed any data.
I have had this a couple of times with Userform_Initialize codes, suddenly not working I am unsure why?
Private Sub UserForm_Initialize()
Dim statement As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Users\m\Desktop\csvalues.xls;" & _
"Extended Properties='Excel 8.0;HDR=Yes'"
conn.Open
statement = "SELECT [Sale Monies In] FROM [Description$]"
Set rs = conn.Execute(statement, , adCmdText)
With MoniesInDescription
Do Until rs.EOF
.AddItem CStr(rs.Fields("Sale Monies In").Value)
rs.MoveNext
Loop
End With
rs.Close
conn.Close
End Sub