Hi
I find what you are trying to do a little confusing, but I have put your code in the forn Initialise (sorry Initiliaze) event which seems to work.
Code:
Private Sub UserForm_Initialize()
Dim lngJ As Long
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
cn.Open "TEST"
rs.Open "SELECT * FROM tblJobs", cn, adOpenStatic, adLockReadOnly
For lngJ = 0 To rs.Fields.Count - 1
Sheets("AllActions").Cells(1, lngJ + 1) = rs.Fields(lngJ).Name
Next
Sheets("AllActions").Range("A2").CopyFromRecordset rs
If rs.RecordCount >= 1 Then
If rs.RecordCount = 1 Then
Me.lstActions.RowSource = "AllActions!A2:J" & rs.RecordCount + 1
Me.lstActions.ColumnCount = rs.Fields.Count
Me.lstActions.ColumnHeads = True
Else
Me.lstActions.RowSource = "AllActions!A2:J" & rs.RecordCount + 1
Me.lstActions.ColumnCount = rs.Fields.Count
Me.lstActions.ColumnHeads = True
End If
Else
Me.lstActions.RowSource = "AllActions!A2:J2"
Me.lstActions.ColumnCount = rs.Fields.Count
Me.lstActions.ColumnHeads = True
End If
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
basically I only change the is
+ CStr(findLastRow(Sheets("AllActions").Range("A2"), ""))
To this
& rs.RecordCount + 1
EDIT: which make the if statment "If rs.RecordCount = 1 Then" redundant ?
The only other thing(s) is I am not sure what you do with "strShtName"
or why this "Set adoRS = rs"
Where to you declare/dimension/open the "rs" recordset ??
Also if you do not need the information in the sheet you could populate the list box directly from the record set.
HTH
MTB