Tuesday, 10 September 2013

What is wrong with this VBA Code

What is wrong with this VBA Code

Please tell me what is wrong with this code. It shows error... "The
rowsourcetype property must be set to value list to use this"
Private Sub Form_Load()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String, strItem As String
strSQL = "SELECT CustomerID, CompanyName FROM Customers"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
Do Until rs.EOF
strItem = rs.Fields("CustomerID").Value & ";" _
& rs.Fields("CompanyName").Value
Me.List1.AddItem strItem ' Row Source Type must be Value List
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub

No comments:

Post a Comment